Trying to print columns of pixel values into the particle console from the photon serial port.
Here is my code
int READ_BUF_SIZE = 80;
int readBufOffset = 0;
char readBuf[READ_BUF_SIZE];
while (readBufOffset < READ_BUF_SIZE) {
char Serial_in = Serial1.read();
readBuf[readBufOffset++] = Serial_in;
}
Particle.publish("Serial",String(readBuf) ,80, PRIVATE);
Here is what it currently prints instead of a full list of values.
[‘255’, ‘255’, ‘255’, ‘255’, ‘255’, ‘255’, ‘255’, ‘255’, ‘255’,�����������������V
Particle.publish()
only accepts a subset of possible characters as part of the string.
Most obvious, any pixel that would hold a 0x00 value would terminate the string there and then.
In order to transfer binary data you have to encode it into something like Base64 or Base85 for minimal data consumption.
Or you can encode it as a collection of HEX values if you want the data to be human readable.
This is what it publishes with hex values
[‘0xe9’, ‘0xe9’, ‘0xe7’, ‘0xe8’, ‘0xe9’, ‘0xe9’, ‘0xea’, '0xe9’�����������������V
I wonder how that can by what you sent when looking at your code above.
To me that rather looks like something the cloud event parser makes out off your data.
You are sending an array of bytes which may well contain incompatible values.
My python code sends the data over a rx-tx cable
for y in range(rows):
pixel_string.append(hex(img.get_pixel(x,y)))
y = y + 1
uart.write(str(pixel_string).replace(’,’, ‘’))
time.sleep(1000)
How would you suggest I change the data to hex?
That would have been a valuable info to start with
With that extra insight it might be that you are actually reading the data faster than it is coming in and the �
bytes are actually indicating that fact.
When executing Serial1.read()
against an empty RX buffer will return (int)-1
and squeezing that into a char
will result in a 0xFF
character that may well be reported that way.
Ok ill try and change up the sleep time and see if that has any effect.
Still not able to get past 64 charecters