Hello, I am using Processing to send a start string to the Arduino, which then usually proceeds to send a stream of data back to the computer (it works when I send 'Start' using the serial monitor).
It's not working though and I can see the Arduino recieves the string (I physically sniffed the data on the pins, I also just got the Arduino to repeat what I'd sent) and I know that processing is holding the serial port open so it's not dropping it.
I cant for the life of me figure out why they just wont get along!
Here is the processing code:
import processing.serial.*;
Serial myPort; // The serial port
String b = "Start";
char data[] = {'S', 't', 'a', 'r', 't', '\0'};
String str2 = new String(data);
char inByte;
void setup() {
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[2], 9600);
myPort.buffer(1);
myPort.write(str2);
/*myPort.write('S');
myPort.write('t');
myPort.write('a');
myPort.write('r');
myPort.write('t');*/
}
void draw() {
background(0);
}
void serialEvent(Serial myPort) {
inByte = myPort.readChar();
println(inByte);
}
And here is the Arduino code (it is reading values from an array of thermistors):
#define M_0 8
#define M_1 9
#define M_2 10
#define M1_E 7
#define M2_E 5
#define M3_0 2
#define M3_1 3
#define M3_2 4
#define ROWS 14
#define COLS 14
const int MuxPins1[3] = {M_0, M_1, M_2};
const int MuxPins2[3] = {M3_0, M3_1, M3_2};
int Rij1[(ROWS*COLS)/2]; //resistance magnitude array
int Rij2[(ROWS*COLS)/2]; //resistance magnitude array
int state = 0;
String b="Start";
String bb = "stop";
void setup() {
// put your setup code here, to run once:
pinMode(M_0, OUTPUT);
pinMode(M_1, OUTPUT);
pinMode(M_2, OUTPUT);
pinMode(M1_E, OUTPUT);
pinMode(M2_E, OUTPUT);
pinMode(M3_0, OUTPUT);
pinMode(M3_1, OUTPUT);
pinMode(M3_2, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(A6, INPUT);
digitalWrite(M1_E,HIGH);
digitalWrite(M2_E,HIGH);
selectMuxPin2(0, MuxPins2);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// wait for the START button
if(!state){
while (Serial.available() == 0){
};
while(Serial.available()){
while (!(b==Serial.readString())){
}
}
state = 1;
}
//Do the read
selectMuxPin2(0, MuxPins2);
for (unsigned int row=0; row<ROWS; row++){ // row
selectMuxPin1(row, MuxPins1);
for (unsigned int col=0; col<(COLS/2); col++){
//delay(1);
Rij1[(row*(COLS/2))+col] = analogRead(col);
}
}
selectMuxPin2(1, MuxPins2);
for (unsigned int row=0; row<ROWS; row++){ // row
selectMuxPin1(row, MuxPins1);
for (unsigned int col=0; col<(COLS/2); col++){
//delay(1);
Rij2[(row*(COLS/2))+col] = analogRead(col);
}
}
//Send Values
for (unsigned int row=0; row<ROWS; row++){ // row
for (unsigned int col=0; col<(COLS/2); col++){
Serial.println(Rij1[(row*(COLS/2))+col]);
}
for (unsigned int col=0; col<(COLS/2); col++){
Serial.println(Rij2[(row*(COLS/2))+col]);
}
}
//delay(1);
//check for stop command
if(state&&Serial.available()){
if(bb==Serial.readString()){
state=0;
}
}
}
void selectMuxPin1(unsigned int pin, const int selectPins[]){
pin = pin;
if(pin<7){
digitalWrite(M1_E,LOW);
digitalWrite(M2_E,HIGH);
} else{
pin = pin+1;
digitalWrite(M1_E,HIGH);
digitalWrite(M2_E,LOW);
}
for (int i=0; i<3; i++)
{
if (bitRead(pin,i)==1)
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}
void selectMuxPin2(unsigned int pin, const int selectPins[]){
pin = pin;
for (int i=0; i<3; i++)
{
if (bitRead(pin,i)==1)
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}
I would really appreciate it if anyone can see where I might be going wrong