I'm having trouble receiving multiple characters from serial.
I'm trying to send an integer from Python (which I get from a particular sequence of binary that I want). It's basically a value between 0 and 255 that I'm sending to the arduino. After every value, I send a "*", which is what I'm using as my delimiting value, and then in the arduino code, I'm trying to read each number into a 2D array (there are 64 numbers sent total).
I know the code is fine on the python side, I've printed the values that I'm sending and they're correct (numbers between 0 and 255 with a * at the end). It's just not working properly on the arduino side.
I'm using this to drive an LED cube, each integer value corresponds to the states of 8 LEDs in a row. If I hardcode the array into arduino, it works fine, so I'm pretty sure it's a problem with the serial communication. I can't print the current array out to the serial monitor to debug though, because python's using the serial code.
Arduino code:
void loop() {
String currentValue = "";
for (int layer = 0; layer < 8; layer++) {
for (int row = 0; row < 8; row++) {
while (!Serial.available()) {
;
}
char c = Serial.read();
if (c != '*') {
currentValue += c;
}
else {
currentCube[layer][row] = currentValue.toInt();
currentValue = "";
}
}
}
}
Python code:
def sendCube(cube):
(layers) = len(cube)
(rows, cols) = (len(cube[0]), len(cube[0][0]))
currentBin = ""
currentInt = 0
for layer in xrange(layers):
for row in xrange(rows):
for col in xrange(cols):
if (cube[layer][row][col] == 1):
currentBin += '1'
else:
currentBin += '0'
currentInt = int(currentBin, 2)
arduino.write(str(currentInt) + '*')
currentBin = ""
currentInt = 0
Any ideas on why it's not working?