here is the thing..
i want to connect many arduino pro micro using only 1 mono jack cable for every connection..
so i have grounds...and just 1 pin.
Lets say that i have a transmitter and a receiver (but they can work also vice versa).
I want whenever i connect the transmitter to the receiver, it will know which EXACTLY is the pin that it received the signal and nothing more(like an identification thing)..then when i disconnect the cable i want the receiver to know that this cable is disconnected...
Until know after much thinking and some reading i have concluded that it can work with one of the following options:
- serial communication
the transmitter send a specific char so the receiver knows that this is a specific pin
like this:
receiver code:
bool on = true;
bool pressedCon = false;
bool pressedDisc = false;
SoftwareSerial myCable1(myRxPin, 99);
void setup(){
myCable1.begin(4800);
}
void loop() {
if (myCable1.available()) {
char myID = myCable1.read();
if (myID == '!' && !pressedCon) {
Serial.println("!, on");
pressedCon = true;
pressedDisc = false;
}
}
else if(pressedCon && !pressedDisc){
Serial.println("off");
pressedCon = false;
pressedDisc = true;
}
//do other stuff
}
transmitter code:
SoftwareSerial myCable1(99, 2);
char myIDChar = '!';
void loop() {
myCable1.write(myIDChar);
//do other stuff
}
The problem with this code is that it works..but not always..
when i connect the cable i the "!, on" message..when i disconnect i see the "off" BUT after some connect/disconnect it stops working correctly..
so, when the cable is disconnected what happens to the char? is it waiting to be transmitted? do transmitter and receiver send and receive at the same exact time? what happen when the transmitter sends but receiver does "other stuff"
- another possible way is: transmitter send specific voltage and receiver knows that for example 3.5V is this specific ID (the char '!'), 3.6V will be the char '*' etc.. but again this needs voltage dividers, or DAC, or PWM that i guess will not work, because the receiver's analogRead cannot read the "average" of PWM, but it will read "100 Hz cycle"..
any opinion will be highly appreciated..