I'm trying to pass a dynamic number of characters from a Python program on my Raspberry Pi to my Adafruit Feather 32u4 radio. After discovering that using the available() function truncates my character array to 64 bytes I searched the web and found this link below.
http://forum.arduino.cc/index.php?topic=396450.0
I'm using Example #2 and according to the link above I can change the array length to what I choose but I'm finding that it's working in a non-linear fashion.
This is my modified test using Example 2:
// Example 2 - Receive with an end-marker
#include <SPI.h>
const byte numChars = 1500;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
void setup() {
Serial.begin(74880);
Serial.println("<Arduino is ready>");
Serial1.begin(74880);
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial1.available() > 0 && newData == false) {
rc = Serial1.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
Note that the baud rate is the highest I can use without getting garbage characters.
Serial1 is the serial coming from the Pi. My test string from the Pi is
Changing the size of the numChars to 500 yields the most but increasing it yields fewer characters. From where I see, the number of characters does not act in a linear fashion. I'm sure there's something else going on, but I'm not seeing it.
numChars = 650
This just in ... INSERT INTO weathers(currentWindSpeed, currentWindGust, totalRain, bmp180Temperature, bmp180Pressure, bmp180Altitude, bmp180SeaLevel, ou
numChars = 500 //(closest to all the characters)
This just in ... INSERT INTO weathers(currentWindSpeed, currentWindGust, totalRain, bmp180Temperature, bmp180Pressure, bmp180Altitude, bmp180SeaLevel, outsidetemperature, outsideHumidity, currentwinddirection, currentWindDirectionVoltage) VALUES(0.000, 0.000,
numChars = 400
This just in ... INSERT INTO weathers(currentWindSpeed, currentWindGust, totalRain, bmp180Temperature, bmp180Pressure, bmp180Altitude, bmp180SeaLevel, outsidet
numChars = 1000
This just in ... INSERT INTO weathers(currentWindSpeed, currentWindGust, totalRain, bmp180Temperature, bmp180Pressure, bmp180Altitude, bmp180SeaLevel, outsidetemperature, outsideHumidity, currentwinddirection, currentWindDirectionVoltage) VALUES(0
numChars = 1500
This just in ... INSERT INTO weathers(currentWindSpeed, currentWindGust, totalRain, bmp180Temperature, bmp180Pressure, bmp180Altitude, bmp180SeaLevel, outsidetemperature, outsideHumidity, currentwinddirection, currentWindDirectionVolta
Looking at this reference seems to suggest that I can create a large array? In this test my string length is 312 characters but the actual number is likely longer and dynamic.
https://www.arduino.cc/en/Reference/Array
Clearly, there's something going on that I'm not understanding and a pointer to what I'm doing wrong would be helpful.