Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
Sistemi integrati - raspberry pi non riceve da rs485collegato all uart e ad arduino
Forum - Sistemi integrati - raspberry pi non riceve da rs485collegato all uart e ad arduino

Avatar
alex1995 (Normal User)
Expert


Messaggi: 212
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 21:43
Domenica, 12/04/2015
salve, ho collegato un arduino mega e un raspberry pi tramite il modbus rs485 usando questo modulo e questo schema https://www.homegear.eu/index.php/RS485_Serial_Module e questo sketch (l' ho usato per provare):

Codice sorgente - presumibilmente Delphi

  1. /* YourDuino SoftwareSerialExample1
  2.    - Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
  3.    - Connect this unit Pins 10, 11, Gnd
  4.    - Pin 3 used for RS485 direction control
  5.    - To other unit Pins 11,10, Gnd  (Cross over)
  6.    - Open Serial Monitor, type in top window.
  7.    - Should see same characters echoed back from remote Arduino
  8.  
  9.    Questions: terry@yourduino.com
  10. */
  11.  
  12. /*-----( Import needed libraries )-----*/
  13. #include <SoftwareSerial.h>
  14. /*-----( Declare Constants and Pin Numbers )-----*/
  15. #define SSerialRX        10  //Serial Receive pin
  16. #define SSerialTX        11  //Serial Transmit pin
  17.  
  18. #define SSerialTxControl 3   //RS485 Direction control
  19.  
  20. #define RS485Transmit    HIGH
  21. #define RS485Receive     LOW
  22.  
  23. #define Pin13LED         13
  24.  
  25. /*-----( Declare objects )-----*/
  26. SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
  27.  
  28. /*-----( Declare Variables )-----*/
  29. int byteReceived;
  30. int byteSend;
  31.  
  32. void setup()   /****** SETUP: RUNS ONCE ******/
  33. {
  34.   // Start the built-in serial port, probably to Serial Monitor
  35.   Serial.begin(9600);
  36.   Serial.println("YourDuino.com SoftwareSerial remote loop example");
  37.   Serial.println("Use Serial Monitor, type in upper window, ENTER");
  38.  
  39.   pinMode(Pin13LED, OUTPUT);  
  40.   pinMode(SSerialTxControl, OUTPUT);    
  41.  
  42.   digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver  
  43.  
  44.   // Start the software serial port, to another device
  45.   RS485Serial.begin(4800);   // set the data rate
  46.  
  47. }//--(end setup )---
  48.  
  49.  
  50. void loop()   /****** LOOP: RUNS CONSTANTLY ******/
  51. {
  52.   digitalWrite(Pin13LED, HIGH);  // Show activity
  53.   if (Serial.available())
  54.   {
  55.     byteReceived = Serial.read();
  56.    
  57.     digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit  
  58.     RS485Serial.write(byteReceived);          // Send byte to Remote Arduino
  59.    
  60.     digitalWrite(Pin13LED, LOW);  // Show activity    
  61.     delay(10);
  62.     digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit      
  63.   }
  64.  
  65.   if (RS485Serial.available())  //Look for data from other Arduino
  66.    {
  67.     digitalWrite(Pin13LED, HIGH);  // Show activity
  68.     byteReceived = RS485Serial.read();    // Read received byte
  69.     Serial.write(byteReceived);        // Show on Serial Monitor
  70.     delay(10);
  71.     digitalWrite(Pin13LED, LOW);  // Show activity  
  72.    }  
  73.  
  74. }//--(end main loop )---
  75.  
  76. /*-----( Declare User-written Functions )-----*/
  77.  
  78. //NONE
  79. //*********( THE END )***********



ma ho un problema: arduino trasmette e riceve ma il raspberry trasmette solo.

per trasmettere dati dal raspberry io do questo comando:

Codice sorgente - presumibilmente Plain Text

  1. echo '1' > /dev/ttyAMA0



e per leggere:

Codice sorgente - presumibilmente Plain Text

  1. od -x < /dev/ttyAMA0



e non appare niente quando trasmetto.

potete aiutarmi?


PM Quote