I have been able to put together the essential parts of my Dromes4All mobile robot so now I have been working on establishing a communication system. I had previously decided to use infrared communication just because I have never used it before and it looked interesting. I settled on the NEC encoder/decoder module YS-IRTM V3.08. There is some information available for this although it is not that easy to find - well I didn't find it easy to find, and it just wasn't that easy to get going.
The YS-IRTM module has simples connections, just power (0V and +5V) and serial communications (Tx and Rx). There is no handshaking. The Rx connections to the Tx on the Arduino and the Tx to the Rx on the Arduino and the circuit is illustrated below.
The modules uses a simple serial communication protocol,, no handshaking, with a default Baud rate of 9600. To transmit data a five byte sequence is needed, with the first two bytes being the command to transmit the following three bytes over the IR link. These first two bytes are 0xA1 and 0xF1. The following three bytes are the data to be transmitted and I think can be anything, say 0x41 and 0x42 and 0x45 say.
I made no progress at all for many hours as the modules just would not transmit. Eventually I gave up trying to use an Arduino to create the codes and searched around for an existing IR hand controller for TV/video/radio and so on. Having tried about 6 different ones with no success I amazingly had one, from an old DAB radio which enabled me to receive the codes and encouraged me to continue trying.
After carefully looking at many different Blogs (most of which were from people being unsuccessful) I found one snippet of code that was claimed to work. It looked much the same as I was using but I thought - why not just try it out, and hey presto - it worked. Then it was easy to get bi-directional communication working using Arduinos.
This is the receiving programme.
/*
Receives IR data using a NEC IR Transceiver
You have to use
Serial.write()
Dubbie Dubbie
19th May'21
Just for Fun
*/
void setup() {
Serial.begin(9600);
}
void loop()
char value;
value = " ";
while (1)
{
while (Serial.available() < 1)
{
delay(1);
} /* while */
value = Serial.read();
Serial.print(value,HEX);
Serial.print(' ');
} /* while */
} /* loop */
and this is the transmitting programme.
uint8_t my_serial_bytes[5]={0xA1, 0xF1, 'A', 'B', 0x45};
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
Serial.write(my_serial_bytes,sizeof(my_serial_bytes));
delay(4000); // delay 5sec
}
It took me two whole days just to get the two modules talking to the Arduinos and then to each other. The NEC modules use serial communication but it is not ASCII encoded as such and you have to use binary values. So although you might think using Serial.print() would work, it doesn't, you have to use Serial.write(). I have looked into this and I still do not really understand the difference between these two functions. However, the essence is that if you use Serial.write() it works, otherwise it doesn't! and can lead to a great deal of hair pulling and frustration, long periods of staring blankly and possibly even some bad words.
See below for a video of the working system.
So now I need to add this to the Dromes4All chassis and I will have a controllable Drome (Hopefully.) Sadly, I do not think I will be able to get four Dromes working by the deadline; too much 3D printing and soldering. I'm hoping for one complete one working which I think will have to be just DromeOne instead of Dromes4All.
Dubbie
Top Comments