And then copy the array into a global array after you’re done. But yeah. Regardless, i’m here with another stupid question.
Why won’t this code work? Skip all the complicated functions - all that matters is the setup and the loop, as everything is stripped out.
Arduino 1:
String InputBuffer = String();
int Pins[6] = {3,5,6,9,10,11};
boolean Direction[6] = {1,2,4,7,8,12};
void setup() {
Serial.begin(9600);
// Serial.println("Arduino ROV reporting for Duty");
// for(int i = 0; i > 5; i++){
// pinMode(Pins[i], OUTPUT);
// pinMode(Direction[i], OUTPUT);
// } //Init Pins to Output
}
boolean ReadIncoming(){
while (Serial.available() > 0) {
InputBuffer.concat(char(Serial.read())); //Read until Pound sign
if (InputBuffer.endsWith('
Arduino 2:
#include <NewSoftSerial.h>
String InputBufferComp = String();
String BitBuffer = String();
NewSoftSerial BitSerial(2,3);
boolean ReadIncomingSerial(){
while (Serial.available() > 0) {
InputBufferComp.concat(char(Serial.read())); //Read until Pound sign
if (InputBufferComp.endsWith('
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with “received”, which will make arduino two print “Received!” in serial monitor.
It isn’t. It loops, keeps sending 1234$, but nothing’s coming back.
)){ //Note, Infinite loop if Pound not found
InputBuffer = InputBuffer.replace(’
Arduino 2:
§DISCOURSE_HOISTED_CODE_1§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with "received", which will make arduino two print "Received!" in serial monitor.
It isn't. It loops, keeps sending 1234$, but nothing's coming back.
,' ');
InputBuffer = InputBuffer.trim(); //Input Buffer is a global Var
return true; //True if Pound sign returned, remove Pound sign
}
}
}
boolean ControlMotor(){
char TempArray[5];
if (InputBuffer.length() == 4){
InputBuffer.toCharArray(TempArray, sizeof(TempArray));
int InputSpeed = atoi(TempArray); //Bad C code right here
int PinRef = InputSpeed;
while(PinRef >= 10)
PinRef /= 10;
InputSpeed = InputSpeed - (PinRef * 1000); //Minus first digit
if ((PinRef <= 5) && (InputSpeed > 0) && (InputSpeed < 512)){
Serial.print("Motor Control Init: Motor Pin ");
Serial.println(Pins[PinRef]); //Lookup PinRef within Pins Array
Serial.print("Motor Direction: ");
Serial.println(InputSpeed <= 255);
Serial.print("Motor Speed: ");
Serial.println(InputSpeed);
Serial.print("$");
// if (InputSpeed <= 255)
// digitalWrite(Direction[PinRef], HIGH);
// else{
// digitalWrite(Direction[PinRef], LOW);
// InputSpeed = InputSpeed - 255;
// }
// analogWrite(Pins[PinRef], InputSpeed);
// return true;
}
}
return false;
}
void loop() {
if (Serial.available()) Serial.println("Received");
}
Arduino 2:
§_DISCOURSE_HOISTED_CODE_1_§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with “received”, which will make arduino two print “Received!” in serial monitor.
It isn’t. It loops, keeps sending 1234$, but nothing’s coming back.
)){ //Note, Infinite loop if Pound not found
return true; //True if Pound sign returned, remove Pound sign
}
}
}
boolean ReadBitSerial(){
while (BitSerial.available() > 0) {
BitBuffer.concat(char(BitSerial.read())); //Read until Pound sign
if (BitBuffer.endsWith(’
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with "received", which will make arduino two print "Received!" in serial monitor.
It isn't. It loops, keeps sending 1234$, but nothing's coming back.
)){ //Note, Infinite loop if Pound not found
InputBuffer = InputBuffer.replace('
Arduino 2:
§_DISCOURSE_HOISTED_CODE_1_§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with “received”, which will make arduino two print “Received!” in serial monitor.
It isn’t. It loops, keeps sending 1234$, but nothing’s coming back.
,’ ');
InputBuffer = InputBuffer.trim(); //Input Buffer is a global Var
return true; //True if Pound sign returned, remove Pound sign
}
}
}
boolean ControlMotor(){
char TempArray[5];
if (InputBuffer.length() == 4){
InputBuffer.toCharArray(TempArray, sizeof(TempArray));
int InputSpeed = atoi(TempArray); //Bad C code right here
int PinRef = InputSpeed;
while(PinRef >= 10)
PinRef /= 10;
InputSpeed = InputSpeed - (PinRef * 1000); //Minus first digit
if ((PinRef <= 5) && (InputSpeed > 0) && (InputSpeed < 512)){
Serial.print("Motor Control Init: Motor Pin ");
Serial.println(Pins[PinRef]); //Lookup PinRef within Pins Array
Serial.print("Motor Direction: ");
Serial.println(InputSpeed <= 255);
Serial.print(“Motor Speed: “);
Serial.println(InputSpeed);
Serial.print(”$”);
// if (InputSpeed <= 255)
// digitalWrite(Direction[PinRef], HIGH);
// else{
// digitalWrite(Direction[PinRef], LOW);
// InputSpeed = InputSpeed - 255;
// }
// analogWrite(Pins[PinRef], InputSpeed);
// return true;
}
}
return false;
}
void loop() {
if (Serial.available()) Serial.println(“Received”);
}
Arduino 2:
§DISCOURSE_HOISTED_CODE_1§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with "received", which will make arduino two print "Received!" in serial monitor.
It isn't. It loops, keeps sending 1234$, but nothing's coming back.
)){ //Note, Infinite loop if Pound not found
return true; //True if Pound sign returned, remove Pound sign
}
}
}
void setup() {
Serial.begin(9600);
BitSerial.begin(9600);
Serial.println("Arduino Shore reporting for Duty");
}
void loop() {
// if (ReadIncomingSerial()){
// Serial.println("Incoming data from Computer.");
// BitSerial.println(InputBufferComp);
// Serial.println(BitSerial.available(), DEC);
// Serial.println(InputBufferComp);
// InputBufferComp = "";
// }
// if (ReadBitSerial()){
// Serial.println("Incoming data from ROV.");
// Serial.print(BitBuffer);
// Serial.println(" :Rov");
// BitBuffer = "";
// }
BitSerial.println("1234$");
if (BitSerial.available()) Serial.println("Received!");
}
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with “received”, which will make arduino two print “Received!” in serial monitor.
It isn’t. It loops, keeps sending 1234$, but nothing’s coming back.
)){ //Note, Infinite loop if Pound not found
InputBuffer = InputBuffer.replace(’
Arduino 2:
§DISCOURSE_HOISTED_CODE_1§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with "received", which will make arduino two print "Received!" in serial monitor.
It isn't. It loops, keeps sending 1234$, but nothing's coming back.
,' ');
InputBuffer = InputBuffer.trim(); //Input Buffer is a global Var
return true; //True if Pound sign returned, remove Pound sign
}
}
}
boolean ControlMotor(){
char TempArray[5];
if (InputBuffer.length() == 4){
InputBuffer.toCharArray(TempArray, sizeof(TempArray));
int InputSpeed = atoi(TempArray); //Bad C code right here
int PinRef = InputSpeed;
while(PinRef >= 10)
PinRef /= 10;
InputSpeed = InputSpeed - (PinRef * 1000); //Minus first digit
if ((PinRef <= 5) && (InputSpeed > 0) && (InputSpeed < 512)){
Serial.print("Motor Control Init: Motor Pin ");
Serial.println(Pins[PinRef]); //Lookup PinRef within Pins Array
Serial.print("Motor Direction: ");
Serial.println(InputSpeed <= 255);
Serial.print("Motor Speed: ");
Serial.println(InputSpeed);
Serial.print("$");
// if (InputSpeed <= 255)
// digitalWrite(Direction[PinRef], HIGH);
// else{
// digitalWrite(Direction[PinRef], LOW);
// InputSpeed = InputSpeed - 255;
// }
// analogWrite(Pins[PinRef], InputSpeed);
// return true;
}
}
return false;
}
void loop() {
if (Serial.available()) Serial.println("Received");
}
Arduino 2:
§_DISCOURSE_HOISTED_CODE_1_§
Arduino 1 is powered by a 9 volt battery, and the Tx pin is connected to pin 2 of Arduino 2, and Rx pin is connected to pin 3 of the Arduino 2.
As you can see, Arduino two initializes Serial and NewSoftSerial. It then repeatedly tries to send something to Arduino 1, and Arduino one is supposed to reply with “received”, which will make arduino two print “Received!” in serial monitor.
It isn’t. It loops, keeps sending 1234$, but nothing’s coming back.