Jump to content

Component: API (ESP32) (API Slave Devices)

From Flowcode Help
Author Matrix TSL
Version 2.0
Category API Slave Devices


API (ESP32) component

Connects to an ESP32 device running the API Firmware allowing the board to become a slave to the Flowcode Embedded simulation or Flowcode App Developer. Supports: Digital IO / ADC / I2C / SPI / PWM / UART See Flowcode Help Wiki for firmware.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_ESP32_API_Comp.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_ESP32_API_Comp.fcfx

Detailed description

The App Developer (ESP32) component allows an ESP32 board to be controlled from within the Flowcode simulation runtime.

To allow Flowcode to communicate and control the ESP32 hardware the board must first be pre-programmed with dedicated firmware.

The firmware source project can be downloaded from here.

You will need to set your WIFI SSID and Password near the top of Main to allow the ESP module to connect to your network.

ESP32 App Developer Firmware

More information about the workings of the firmware project can be found on the FiniteStateMachine page.


The IP Address to the ESP32 hardware is selected via the SCADA_ESP32 component IP Address property.

When building the component into a App Developer project remember to expose the IP Address property to allow the end user to select the address for the hardware.


The console window can display data in two modes which is set via a component property.

  • fixed statistics showing IO / ADC inputs / PWM
  • scrolling log showing all commands and returns

Examples

Pin Mapping

Here is a table showing how the App Developer Slave digital pins are mapped on the device.

Please note pins 34, 35, 36, 39 are only capable of digital inputs and cannot be used as digital outputs.

App Developer Slave Digital Pin 0 1 2 3 4 5 12 13 14 15 16 17 18 19 21 22 23 25 26 27 32 33 34 35 36 39
Device Port Pin A0 A1 A2 A3 A4 A5 A12 A13 A14 A15 A16 A17 A18 A19 A21 A22 A23 A25 A26 A27 B0 B1 B2 B3 B4 B7
GPIO Number 0 1 2 3 4 5 12 13 14 15 16 17 18 19 21 22 23 25 26 27 32 33 34 35 36 39


Here is a table showing how the App Developer Slave analogue pins are mapped on the device.

Please note not all analogue input pins are available as peripheral ADC2 is not accesible when WIFI/Bluetooth is active. Only the pins shown are available.

App Developer Slave Analogue Pin 0 3 4 5 6 7
Device Port Pin B4 B7 B0 B1 B2 B3
GPIO Number 36 39 32 33 34 35


Here is a table showing how the App Developer Slave peripheral pins are mapped on the device.

Please note that PWM channels are tied in pairs and so channel 0 and 1 use the same internal timer peripheral. They will always run at the same frequency and when enabling channel 1 channel 0 duty will be reset to 0% and visa versa.


App Developer Slave Peripheral Pin I2C 0 SDA I2C 0 SCL I2C 1 SDA I2C 1 SCL SPI 0 MOSI SPI 0 MISO SPI 0 SCK SPI 1 MOSI SPI 1 MISO SPI 1 SCK UART 0 RX UART 0 TX UART 1 RX UART 1 TX PWM 0 PWM 1 PWM 2 PWM 3 PWM 4 PWM 5 PWM 6 PWM 7 PWM 8 PWM 9 PWM 10 PWM 11 OneWire
Device Port Pin A13 A12 A15 A14 A13 A12 A14 A23 A19 A18 A26 A25 B0 B1 A0 A2 A4 A5 A12 A13 A14 A15 A16 A17 A18 A19 A21
GPIO Number 13 12 15 14 13 12 14 23 19 18 26 25 32 33 0 2 4 5 12 13 14 15 16 17 18 19 21


PortA = GPIO pins 0 - 31 : A0 = GPIO 0

PortB = GPIO pins 32 - 39 : B0 = GPIO 32

Macro reference

ADCSample10

ADCSample10
Reads the voltage present on an Analog pin as an 12-bit value range 0-4095 
- BYTE ADCChannel
Range: 0, 3-7 
- UINT Return


ADCSample8

ADCSample8
Reads the voltage present on an Analog pin as an 8-bit value range 0-255 
- BYTE ADCChannel
Range: 0, 3-7 
- BYTE Return


ADCSampleArray10

ADCSampleArray10
Reads the voltage present on an Analog pin as an 10-bit value range 0-1023 Performs the selected number of samples with the selected time in microseconds in between samples and returns each sample in a single packet 
- BYTE ADCChannel
Range: 0, 3-7 
- BYTE SampleCount
Range: 1- 32 
- UINT SampleDelay
Delay in us between each sample 
- UINT Samples
10-bit samples returned from the function 
- VOID Return


ADCSampleArray8

ADCSampleArray8
Reads the voltage present on an Analog pin as an 8-bit value range 0-255 Performs the selected number of samples with the selected time in microseconds in between samples and returns each sample in a single packet 
- BYTE ADCChannel
Range: 0, 3-7 
- BYTE SampleCount
Range: 1- 32 
- UINT SampleDelay
Delay in us between each sample 
- BYTE Samples
8-bit samples returned from the function 
- VOID Return


ADCSampleAverage10

ADCSampleAverage10
Reads the voltage present on an Analog pin as an 10-bit value range 0-1023. Performs the selected number of samples with the selected time in microseconds in between samples 
- BYTE ADCChannel
Range: 0, 3-7 
- BYTE SampleCount
Range: 1- 100 
- BYTE SampleDelay
Delay in us between each sample 
- UINT Return


ADCSampleAverage8

ADCSampleAverage8
Reads the voltage present on an Analog pin as an 8-bit value range 0-255 Performs the selected number of samples with the selected time in microseconds in between samples 
- BYTE ADCChannel
Range: 0, 3-7 
- BYTE SampleCount
Range: 1- 100 
- BYTE SampleDelay
Delay in us between each sample 
- BYTE Return


ADCSetPrechargeTime

ADCSetPrechargeTime
Specifies the precharge time for the ADC input readings in microseconds. The longer the time the more immune to noise the reading will be. 
- BYTE ChargeTime
Default 10 
- VOID Return


ADCSetReferenceVoltage

ADCSetReferenceVoltage
Specified the reference setting for ADC reads. 
- BYTE RefType
0=AREF, 1=VCC, 3=Internal 1.1V 
- VOID Return


I2CInitialise

I2CInitialise
Initialise the I2C module ready for communications 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Baud
0=100KHz, 1=400KHz, 2=1MHz 
- VOID Return


I2CReceive

I2CReceive
Receive a byte using the I2C bus 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BOOL Last
Last byte to receive: Range 0-1 
- BYTE Return


I2CRestart

I2CRestart
Put the I2C Module into Restart mode 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- VOID Return


I2CSend

I2CSend
Transmit a byte using the I2C bus 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE DataOut
 
- BOOL Return


I2CStart

I2CStart
Put the I2C Module into Start mode 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- VOID Return


I2CStop

I2CStop
Put the I2C Module into Stop mode 
- BYTE Channel
 
- VOID Return


I2CTransInit

I2CTransInit
Initialises the I2C Transaction mode with the 7-bit device address 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE DeviceAddress
7-bit Device Address 
- BYTE Baud
0=100KHz, 1=400KHz, 2=1MHz 
- VOID Return


I2CTransReceive

I2CTransReceive
Receives an I2C Transaction on the selected I2C channel. Returns the number of bytes received. 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Data
Data variable to receive into 
- UINT Count
Number of bytes to receive 
- UINT Return


I2CTransSend

I2CTransSend
Sends an I2C Transaction on the selected I2C channel. Returns the number of bytes sent. 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Data
Data to send 
- UINT Count
Number of bytes to send out, MS bit 0x8000 signifies no Stop if set 
- UINT Return


IOGetInputPin

IOGetInputPin
Sets the selected digital pin to an input and reads the input state. 
- BYTE Pin
Range: 0-29 
- BOOL Return


IOSetOutputPin

IOSetOutputPin
Sets the selected digital pin to an output and assigns the output state. 
- BYTE Pin
Range: 0-29 
- BOOL State
Range: 0-1 
- VOID Return


Initialise

Initialise
Initialise the comms to the Arduino board ready for commands to be sent. 
- VOID Return


OneWireBusReset

OneWireBusReset
Issue a 'ping' on the bus. If there is at least one sensor on the bus then it will generate a presence pulse. Returns 0 if a presense pulse was detected Returns 1 no device was detected 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BOOL Return


OneWireGetDeviceCount

OneWireGetDeviceCount
Returns the number of devices found by the last ScanBus operation. 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Return


OneWireGetIDByte

OneWireGetIDByte
Returns a single byte of the 64-Bit lasered ROM code, 255 on error 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Device
Device ID - Range: 0 - NumDevices - 1 
- BYTE ByteIndex
Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC 
- BYTE Return


OneWireInitialise

OneWireInitialise
Initialise the OneWire module ready for communications 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- VOID Return


OneWireMatchROM

OneWireMatchROM
Performs a reset followed by the MatchROM code and then the 8-bit ROM code. 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE FamilyCode
 
- BYTE SerialNumber
 
- VOID Return


OneWireReceiveByte

OneWireReceiveByte
Receives a byte from the one wire bus a bit at a time 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Return


OneWireScanBus

OneWireScanBus
Scans the one wire bus to detect all connected devices. Returns the number of one wire devices found. 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Return


OneWireSkipROM

OneWireSkipROM
Performs a bus reset and the sends the SkipROM command byte 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- VOID Return


OneWireTransmitByte

OneWireTransmitByte
Transmit a byte to the one wire bus a bit at a time 
- BYTE Channel
Channel Index: Range 0 - I2C Bus Count - 1 
- BYTE Data
 
- VOID Return


PWMDisable

PWMDisable
Disable a PWM output 
- BYTE Channel
Range: 0-11 
- VOID Return


PWMEnable

PWMEnable
Enable a PWM output 
- BYTE Channel
Range: 0-11 
- VOID Return


PWMSetDuty

PWMSetDuty
Sets the duty for the PWM output 
- BYTE Channel
Range: 0-11 
- BYTE Duty
 
- VOID Return


PWMSetFrequency

PWMSetFrequency
Sets PWM frequency in Hz 
- BYTE Channel
Range: 0 - 11 
- LONG Frequency
Frequency (Hz) 
- VOID Return


SPIInitialise

SPIInitialise
Initialsie the SPI module ready for communications 
- BYTE Channel
Channel Index: Range 0 - SPI Bus Count - 1 
- VOID Return


SPIPrescaler

SPIPrescaler
Modify the speed of the SPI bus 
- BYTE Channel
Channel Index: Range 0 - SPI Bus Count - 1 
- BYTE Prescaler
Range: 0-2 
- VOID Return


SPITransfer

SPITransfer
Transfer a byte using the SPI bus 
- BYTE Channel
Channel Index: Range 0 - SPI Bus Count - 1 
- BYTE DataOut
 
- BYTE Return


SPITransferTrans

SPITransferTrans
Transfer an array of bytes using the SPI bus 
- BYTE Channel
Channel Index: Range 0 - SPI Bus Count - 1 
- UINT Count
Number of bytes to send and receive 
- BYTE DataOut
Outgoing data 
- BYTE DataIn
Incoming data 
- VOID Return


UARTBaud

UARTBaud
Control the communications rate of the UART module 
- BYTE Channel
Channel Index: Range 0 - UART Bus Count - 1 
- BYTE Rate
0=1200, 1=2400, 2=4800, 3=9600, 4=19200, 5=38400, 6=57600, 7=115200 
- VOID Return


UARTCheckRX

UARTCheckRX
Check to see if the UART module has received any data 
- BYTE Channel
Channel Index: Range 0 - UART Bus Count - 1 
- BYTE Return


UARTInitialise

UARTInitialise
Initialise the UART module ready for communications 
- BYTE Channel
Channel Index: Range 0 - UART Bus Count - 1 
- VOID Return


UARTReceive

UARTReceive
Receives a data byte from the UART. Recommend calling the UARTCheckRx function first to ensure data is available. 
- BYTE Channel
Channel Index: Range 0 - UART Bus Count - 1 
- BYTE Return


UARTSend

UARTSend
Send a byte via the UART module 
- BYTE Channel
Channel Index: Range 0 - UART Bus Count - 1 
- BYTE Data
Data Byte to send. Range: 0-255 
- VOID Return


Property reference

Properties
Connection
ESP IP Address
IP Address of the Raspbery Pi we want to control 
ESP Port
Port number we want to communicate on. Default 1234 
Network Interface
Some computers may have several network interfaces such as ethernet ports and wifi access. Select the correct network interface for the network you wish to connect to. Use the IP address to confirm you are connected to the right network. 
IP Address
IP Address of the selected network interface. 
API Peripherals
Digital IO
 
Analog Input
 
Analog Output
 
PWM Output
 
I2C Bus
 
SPI Bus
 
UART
 
OneWire
 
SERVO
 
Console
Console Log
Create an automatic console log of the commands sent to the ESP 
Log Mode
Controls how the console data is formatted. Fixed statistics gives an easy to read overview of the IO, Analog and PWM functionality Command Log gives a more in depth analysis of the outgoing commands and incoming returns ASCII mode allows serial data to be shown in raw text form, other commands are shown as in the Command Log mode