Hello all.
I am working on a piece of code which compiles data from many sensors (for now represented as random data for testing purposes) into a JSON-formatted string to send over serial to an RPI.
I noticed while watching the serial monitor that the timestamp readout for the messages seem to come in groups of 2-3 messages all in the same millisecond, despite my code having a delay(). This might not be a problem but it makes me curious as to whether something is going on with my buffer filling up, or something else I do not know about.
The code:
#include <Wire.h>
#include <SensorMessage.h>
SensorMessage sensorMessage(0);
bool toggle = true;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if(toggle == true){
sensorMessage.PT_HE = 1; ///< 16 bit unsigned integer representing the Helium presurrant supply
sensorMessage.PT_Purge = random(0,500); ///< 16 bit unsigned integer representing the Nitrogen purge supply
sensorMessage.PT_Pneu = random(0,500); ///< 16 bit unsigned integer representing the Nitrogen pneumatic supply
sensorMessage.PT_FUEL_PV = random(0,500); ///< 16 bit unsigned integer representing the Gas above fuel in pressure vessel
sensorMessage.PT_LOX_PV = random(0,500); ///< 16 bit unsigned integer representing the Gas above LOX in pressure vessel
sensorMessage.PT_FUEL_INJ = random(0,500); ///< 16 bit unsigned integer representing the Fuel pressure before entering chamber
sensorMessage.PT_CHAM = random(0,500); ///< 16 bit unsigned integer representing the Chamber pressure
sensorMessage.TC_FUEL_PV = random(0,500); ///< 16 bit unsigned integer representing the Gas above fuel in pressure vessel (possible surface mount)
sensorMessage.TC_LOX_PV = random(0,500); ///< 16 bit unsigned integer representing the Gas above LOX in pressure vessel (possible surface mount)
sensorMessage.TC_LOX_Valve_Main = random(0,500); ///< 16 bit unsigned integer representing the External sensor for valve chill in and force
sensorMessage.RC_LOX_Level = random(0,500); ///< 16 bit unsigned integer representing the Capacitive level sensor of LOX in pressure vessel
sensorMessage.FT_Thrust = random(0,500); ///< 16 bit unsigned integer representing the Load cell that measures thrust of engine
sensorMessage.Send();
delay(10);
//toggle = false;
}
}
It relies on a custom library called "SensorMessage" which has this in its header file:
#include "Arduino.h"
#include "SensorMessage.h"
/**
* @brief Construct a new Sensor Message:: Sensor Message object
*
* @param startCount
*/
SensorMessage::SensorMessage(int startCount)
{
count = startCount;
}
/**
* @brief Builds and sends a serial information.
*
*/
void SensorMessage::Send()
{
this->SetBuffer();
Serial.println(buff);
}
/**
* @brief Set the Buffer object
*
*/
void SensorMessage::SetBuffer()
{
sprintf(buff, "{\"PT_HE\":%hu,\"PT_Purge\":%hu,\"PT_Pneu\":%hu,\"PT_FUEL_PV\":%hu,\"PT_LOX_PV\":%hu,\"PT_FUEL_INJ\":%hu,\"PT_CHAM\":%hu,\"TC_FUEL_PV\":%hu,\"TC_LOX_PV\":%hu,\"TC_LOX_Valve_Main\":%hu,\"RC_LOX_Level\":%hu,\"FT_Thrust\":%hu}",
this->PT_HE, this->PT_Purge, this->PT_Pneu, this->PT_FUEL_PV, this->PT_LOX_PV, this->PT_FUEL_INJ, this->PT_CHAM, this->TC_FUEL_PV, this->TC_LOX_PV, this->TC_LOX_Valve_Main, this->RC_LOX_Level, this->FT_Thrust);
this->count++;
}
I am trying to extract data as often as possible and continuously, but I do notice that with higher delay() values this effect disappears. What is it about low-delay code that can make this happen?