MichaelJonker / HardwareSerialRS485

Arduino Software for RS485 support with collision detection and message handling capabilities
MIT License
107 stars 29 forks source link

Library port for Raspberry Pi #11

Closed arseniy899 closed 3 years ago

arseniy899 commented 5 years ago

Hello, It's a very nice library for Arduino. But for my project I need to connect multiple Arduino's and a Raspberry Pi. Is it possible to port/convert or wrap the library for using it on Raspberry Pi? P.S.: Possibly I can but I don't get code depths

MichaelJonker commented 5 years ago

Hello arseniy899,

Thanks for the interest in my library. To port the code to a raspberry Pi will be more like a re-write. This code directly interacts with the UART registers on the Atmega chip of the Arduino. Hardware access on the RPi is likely completely different. Not even sure if you can do IO on the RPi by directly accessing the registers of the UART (if there is one) of the RPi. Could also be that its UART has higher level functionality like built-in collision detection (the ESP32 has this - I considered, but haven’t ported to that either).

If there is only one RPi in question, you might want to consider to use an Arduino micro or Leonardo (based on a Atmega 32u4 chip) that acts as a gateway to the RPi. I have used this solution with a PC and Andoid app’s (with a USB on the go cable) based host process that talks and listens to the RS485 bus while respecting the protocol. The 32u4 chips can do this because they have a USB port that is independent from the USART. So one can connect a host (PC, RPi,…) to the USB port, and the USART to the RS485 bus. With such a gateway, the host can use normal terminal like communication with the RS485 bus. You can find a little sketch in this project that implements the gateway functionality and relays messages from the host (USB) to the RS485 bus in the proper way.

Hope this was useful information. If you need more help with the gateway solution, don’t hesitate to ask me..

Have fun with your project!

Regards MichaelJonker

Ps what do you mean by “code depths”

From: arseniy899 notifications@github.com Sent: 11 January 2019 17:30 To: MichaelJonker/HardwareSerialRS485 HardwareSerialRS485@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [MichaelJonker/HardwareSerialRS485] Library port for Raspberry Pi (#11)

Hello, It's a very nice library for Arduino. But for my project I need to connect multiple Arduino's and a Raspberry Pi. Is it possible to port/convert or wrap the library for using it on Raspberry Pi? P.S.: Possibly I can but I don't get code depths

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/MichaelJonker/HardwareSerialRS485/issues/11, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJdhEkgvL38Ljvnv-ATrmgYpDNHa_zs6ks5vCLvqgaJpZM4Z7x1E.

arseniy899 commented 5 years ago

Thanks for your answer. Actually, I thought about using kind of 'gate', e.g. attiny85 with SofwareSerial built in Arduino IDE. But this adds an extra chip on PCB for converting one UART to another UART and making it more expensive. How tightly the library is bound to Arduino registers? I believe, common logic can be separated. And what do you mean under "built-in collision detection" respective to UART?

arseniy899 commented 5 years ago

Just found a project called 'NoCan' A report about Main page As I can see, they have implemented nearly the same we are talking about but with CAN bus. I believe - collision detection is also the problem with a CAN bus. Moreover, RS845 and CAN working in same way (difference in protocols as I think)

MichaelJonker commented 5 years ago

Hi, Sorry for the delay,

I think porting to the Attinty might be easier. On the other hand for creating a gateway you need a device with two independent channels, either two UARTS or a UART and a USB. If not you have the same problem for arbitrating the RS485 bus between two types of communication. Possibly software serial can help though for the second channel (I presume there is one hardware channel).

Build-in collision detection, not fully sure, but I have seen in the specs of the ESP32 some items that would facilitate implementation of a concurrent multi masters RS485 based communication. However, I would have to look into this again.

Concerning CAN, bus: I looked into this option in the beginning. The ‘usage model’ of CAN bus is very much based on remote ‘register’ access (where register do not designate the hardware registers), i.e. a master can read/write data into registers on remote slaves. In my case I needed a pure command responds implementation, hence this disqualified CAN interface already somehow. Furthermore, I did not find any hints that the CAN interface for Arduino would allow a concurrent multi masters bus access. I got the feeling that the “usage model” was centred about well-defined masters. Although it is already some time ago, but if I remember well, one needed to attach external hardware chips that implemented the CAN interface. While in the case of the HardwaerSerail485 library only a RS485 chip was needed.

What are you planning with your project, will you have many Raspberry PI’s, will you deploy any Arduino at all? Why do you need a Raspberry PI, this is almost like a full blown PC, with all the inconveniences of a not-so RT like OS sitting in your way… maybe there a simpler options.

Hope this was useful.

Cheers M

From: arseniy899 notifications@github.com Sent: 12 January 2019 19:53 To: MichaelJonker/HardwareSerialRS485 HardwareSerialRS485@noreply.github.com Cc: Michael Jonker michael.jonker@cern.ch; Comment comment@noreply.github.com Subject: Re: [MichaelJonker/HardwareSerialRS485] Library port for Raspberry Pi (#11)

Just found a project called 'NoCan' A report abouthttps://www.omzlo.com/articles/a-raspberry-pi-can-bus-hat-for-the-omzlo-iot-platform Main pagehttps://www.omzlo.com/articles/the-nocan-platform As I can see, they have implemented nearly the same we are talking about but with CAN bus. I believe - collision detection is also the problem with a CAN bus. Moreover, RS845 and CAN working in same way (difference in protocols as I think)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/MichaelJonker/HardwareSerialRS485/issues/11#issuecomment-453772119, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJdhEotf3XizzNYaj5piDQG8mHHbq3K6ks5vCi7zgaJpZM4Z7x1E.

arseniy899 commented 5 years ago

Hello, Thank you for your reply. Possibly I2C can "play" as the second UART. About CAN bus I read a bit more and found out, that it uses generally the same idea. Each message (not device) contains ID, like ID&text. So, the lower ID, the more message important. Actually, you can assign an ID to every device but that is not required. As for the hardware, I found a module based on MCP2515 but unfortunately, it everywhere comes with SPI interface which is kind a problem with AtTiny. Moreover, I could not find bare IC's to place on my PCB. Speaking about my project, I surely want to use Raspberry Pi because:

Actually, right now I have system, let's call it v. 0.9. It's based on 3 arduinos and works not well enough. With the best regards, Arseniy UPD: I've forgotten. I had ordered a few CAN modules. When they arrive I'll give them a try.