chriskyp
Posts: 5
Joined: Wed Apr 16, 2014 12:05 pm

Sent messages from arduino to RPI

Wed Jun 04, 2014 2:09 pm

Hi to all,
i am using an Arduino UNO as a slave. up until now i have managed to sent and receive numbers from one to the other using this schematic and programming to both: http://blog.oscarliang.net/raspberry-pi ... ected-i2c/ .
On my Arduino i am using an NFC reader and i want to sent the card's UID to my raspberry pi. i have tried lots of methods that i have found but non of them seems to be working for me. this has become frustrating. i just want to get a UID and sent it over to my raspberry pi. could you please help me with this problem?
The code for receiving the UID is:

Code: Select all

{
  NFCserial.listen();                                                                                  
        while (NFCserial.available() > 0) {                        
        boolean success;                                              
        // Buffer to store the returned UID                       
        uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };                      
        uint8_t uidLength;  // Length of the UID                     
        // Wait for an ISO14443A type cards (Mifare, etc.).          
        // When one is found'uid' will be populated with the UID       
        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
        if (success) {                                               
        Serial.println("");                                         
        Serial.print("UID Value: ");                                    
        for (uint8_t i=0; i < uidLength; i++)                          
        {                                                               
        Serial.print(uid[i], HEX);          
        }                                                               
        Serial.println("");                                              
        delay(10000); // Try to read a card every 10 sec               
        }                                                             
        } 
  
Thank you in advance

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Sent messages from arduino to RPI

Wed Jun 04, 2014 2:35 pm

You say that you are able to transfer data via I2C using the tutorial you reference. But you do not seem to be using that method of transferring data in the sample code you posted. If you have a method that works, why not use it?

[Disclaimer: I've never done what you are attempting, I've just glanced at the code as described above... ]
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

chriskyp
Posts: 5
Joined: Wed Apr 16, 2014 12:05 pm

Re: Sent messages from arduino to RPI

Wed Jun 04, 2014 3:53 pm

thank you for your reply DeeJay,
i am using it!
But instead of giving a number and receiving in back i want to sent data such as the UID u have read.
i couldn't convert it to string yet, but when i do i want to sent that to the raspberry pi.
If i try to sent a string now using this code i only receive the HEX equivalent of the first character in my message. that's my whole problem, i don't know if it's the Arduino code or the python code that's wrong. this is my sentdata code. right now i am using one character only just to test it with the same result:

Code: Select all

void sendData(){                                                        
   Wire.write("E");  
}                                

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Sent messages from arduino to RPI

Wed Jun 04, 2014 4:17 pm

Same disclaimer as before.

If I were you I would read the documentation for Wire in the Wiring library for the Arduino to see what arguments the write method takes.

In Oscar Laing's example it just uses an integer.

It seems that in your test case it sends an integer that represents the character. Perhaps there is nothing wrong at all - you just need to translate back to the character in the python receiving script on the RPi end. Similarly, if Wire.write only handles a single integer you will need to step though the 8 elements of the uid object and transmit them one at a time.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

chriskyp
Posts: 5
Joined: Wed Apr 16, 2014 12:05 pm

Re: Sent messages from arduino to RPI

Wed Jun 04, 2014 5:00 pm

thank you very much

User avatar
Douglas6
Posts: 4767
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Sent messages from arduino to RPI

Wed Jun 04, 2014 5:55 pm

With Wiring, you can send up to 32 bytes at a time. On the Pi side, you'll want to use i2c_read_block_data() to read more than a single byte.

chriskyp
Posts: 5
Joined: Wed Apr 16, 2014 12:05 pm

Re: Sent messages from arduino to RPI

Thu Jun 05, 2014 10:19 am

Hi,
I have changed my code to pass the readed NFC tad ID to a string :D
Unfortunately now i have to manage to sent it to my raspberry pi and wire.write doesn't support this operation i think

achrn
Posts: 374
Joined: Wed Feb 13, 2013 1:22 pm

Re: Sent messages from arduino to RPI

Thu Jun 05, 2014 11:17 am

UNO has USB hardware built in, and looks to the device itself like a plain serial port.

Pi has USB hardware built in, and looks to the device itself like a plain serial port.

Sending strings across plain serial ports is really very easy in many languages. Have you considered just sending it across the USB? If you use the existing USB hardware you also avoid voltage conversion issues.

Obviously, this is a 'if you want to go there you don't want to start from here' sort of post, but if you're still having problems getting it to do what you want, you could investigate it as an alternative.

Return to “Interfacing (DSI, CSI, I2C, etc.)”