Column: Electronics design
be aware of is CloseFile. T is can be used if you are opening and closing fi les during the app’s operation. If just opening a single fi le and writing to it for the duration of the app, the CloseFile macro is already called when the app is closed or stopped.
The API (ESP32) component T e API component allows us to connect to our target electronics in order to gather real-world data. T e API hardware, be it ESP, Arduino, etc., must fi rst be pre-programmed with the API fi rmware from the Flowcode wiki (https://www.fl
owcode.co.uk/wiki/index. php?title=Components#API_Slave_ Devices). Specifi c to the ESP32 device, you fi rst
need to add it to your existing Wi-Fi network and then determine its IP address. Details of how to do this are available at: https://www.fl
owcode.co.uk/wiki/index. php?title=Component:_SCADA_(ESP32)_ (SCADA_Slaves)#Detailed_description. Before we communicate with the API
hardware, we must do a couple of things: First, we need to expose some of the component properties to the user. We do this by fi rst selecting the component on the panel or at the top of the ‘properties’ window. We then select the properties we want the user to access, and then right-click to ‘Expose’ the top level. For the ESP API this just includes the ESP IP address; for Arduino, it might include the COM port. T en, refresh ‘properties’.
To read specifi c pins as analogue or
digital, we simply call the ADCSample8/10 and IOGetInputPin macros, as required. Each analogue or digital sample can be stored as a variable before being passed into the CSV fi le using the AddNumber macro. T e API component wiki page lists the specifi c hardware pin connections of the analogue and digital channels.
API components and libraries To use the API components and associated hardware to monitor a more complex value, such as the output from a sensor connected via a bus, can be done by dragging the component for the sensor. T e sensor should have a property called ‘simulate comms’, which virtualises the bus communications. T en, by pointing the sensor’s API property at the API component, we can use virtualised comms to drive the real-world comms.
Exporting the project as an application Once you’re done and the project runs well in simulation, you can export it into a shared application by clicking File -> Export -> Deploy as Flowcode App. T is brings up a menu with settings, where you can choose from various panels and views. T e minimal setup includes the properties window, to allow the user to confi gure the required settings before running the app. T e Components and Resources
tabs should pretty much take care of themselves without adjustment, unless you need to embed resources such as bitmaps or audio fi les into the project export. T e main decision is whether or not
Once we have exposed the properties,
we call the macro to initialise it; this opens a specifi c communications channel to the hardware.
Connections for the bus can, again,
be found on the wiki page for the API component. T en it should just be a case of initialising and sampling the sensor like any other embedded device.
to Bundle the App Developer runtime. Bundling the runtime allows for a single self-contained folder you can zip up and pass around, but the downside is its size – a couple dozen MB. Not bundling the runtime will result in a much smaller fi le that is easier to distribute – but at the cost of having to download the runtime from the Flowcode download page: https://fl
owcode.co.uk/resources/ soſt ware/FlowcodeRuntimeV9_Installer. msi.
T is is just the basics of creating a
data-logging application. A lot more could be added to the app, including graphs, multiple data sources and the control of outputs and recordings.
www.electronicsworld.co.uk November 2021 13
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46