-
Notifications
You must be signed in to change notification settings - Fork 0
Sensor module firmware concept
The sensor module acts as a slave device on the internal I²C bus which responds to data requests from the main module, which acts as a master device. Internally, A sensor module should have variables to store the latest information from it's internal sensing device(s). The stored data should be updated at set intervals within the main loop code of the module.
Firmware Sequence Diagram
Upon startup, the sensor module performs all of its required initialization. Once that is complete, the module joins the I²C bus as a slave device with a certain address (see this page for details). Once all setup is complete, the module loops indefinitely, updating it's internal data storage variables while waiting for any requests from the main module. Upon request, all the latest data in the module will be sent over to the main module.
The data that is sent over the bus is all string based, only ASCII characters are sent. This allows the main module to be able to accept any type of information easily, along with making data transmission from sensor modules more straight forward. The data is sent in chunks of up to 32 bytes (or 32 ASCII characters). Each chunk can represent a key and a value for a data entry.
An example reply from a temperature and humidity sensor module (broken into 4 parts) would look like this:
$temperature@
#25.00 c@
$humidity@
#50.00 %!^
The transmission is done over the bus 4 times. These 4 chunks contain two data keys with one value for each key. In this example, a "temperature" value of 25.00°C and a "humidity" value of 50.00% are sent to the main module.
The sensor module keeps track of how many times it has sent chunks to the main module. The main module simply keeps accepting data until a transmission terminator is sent.
$
referred to as CH_IS_KEY
is used to specify that the following characters represent a key for a type of data that is going to be transmitted (i.e "temperature", "light intensity", etc.)
#
referred to as CH_IS_VALUE
is used to specify that the following characters represent the value of the previous data key. This value could be numerical or alphabetical, depending on the desired output of the sensor module.
Note that it is recommended to include the unit of the value that is being transmitted, and that all data should be in SI units.
@
referred to as CH_MORE
is used to specify that there is more data that will be sent from the sensor module every non final transmission MUST be terminated with this character.
!
referred to as CH_TERMINATE
is a character used to terminate the transmission and let the main module know that there is no more data to be sent.
NOTE A data key MUST have a value be sent after it!
With the current implementation of the firmware, data in each individual I²C transmission can not exceed 32 bytes. This means that there is a 32 character limit (including control characters) to the information that you can send in one chunk.
The main module will also only accept ASCII characters being sent to it (C char
type), any other primitive data type sent to it will result in errors.