element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Attack of the Drones
  • Challenges & Projects
  • Project14
  • Attack of the Drones
  • More
  • Cancel
Attack of the Drones
Blog Dromes4All : IR Communication
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Attack of the Drones to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dubbie
  • Date Created: 19 May 2021 4:29 PM Date Created
  • Views 2200 views
  • Likes 8 likes
  • Comments 2 comments
  • ir comms
  • nano
  • dromes4all
Related
Recommended

Dromes4All : IR Communication

dubbie
dubbie
19 May 2021

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.

 

image

 

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.

 

image

 

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.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

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

  • Sign in to reply

Top Comments

  • beacon_dave
    beacon_dave over 4 years ago +5
    "...I have looked into this and I still do not really understand the difference between these two functions..." I think .write() is just sending the value as is, whereas .print() is converting the value…
  • dubbie
    dubbie over 4 years ago in reply to beacon_dave +2
    Dave, This makes sense. I think I was missing the concept of converting a value into something else. Plus, when you monitor using he Serial Monitor in Arduino it becomes a bit unclear as to what actual…
Parents
  • beacon_dave
    beacon_dave over 4 years ago

    "...I have looked into this and I still do not really understand the difference between these two functions..."

     

    I think .write() is just sending the value as is, whereas .print() is converting the value first into its ASCII encoded representation before sending it as one or more values. e.g.

     

    .write(255) is sent as a single byte:

    255   or   1111 1111

     

    .print(255) is sent as three ASCII encoded bytes:

    '2' '5' '5'    or    50 53 53    or    0011 0010   0011 0101   0011 0101

     

    .print(255, HEX) is sent as two ASCII encoded bytes:

    'F' 'F'   or    70 70   or    0100 0110   0100 0110

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • beacon_dave
    beacon_dave over 4 years ago

    "...I have looked into this and I still do not really understand the difference between these two functions..."

     

    I think .write() is just sending the value as is, whereas .print() is converting the value first into its ASCII encoded representation before sending it as one or more values. e.g.

     

    .write(255) is sent as a single byte:

    255   or   1111 1111

     

    .print(255) is sent as three ASCII encoded bytes:

    '2' '5' '5'    or    50 53 53    or    0011 0010   0011 0101   0011 0101

     

    .print(255, HEX) is sent as two ASCII encoded bytes:

    'F' 'F'   or    70 70   or    0100 0110   0100 0110

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • dubbie
    dubbie over 4 years ago in reply to beacon_dave

    Dave,

     

    This makes sense. I think I was missing the concept of converting a value into something else. Plus, when you monitor using he Serial Monitor in Arduino it becomes a bit unclear as to  what actual values are being transmitted - I'm confusing myself again just thinking about it. I used to know al this stuff - I wonder where my brain went?

     

    Dubbie

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube