Pc to Two Arduino Nano with MAX485 and usb TTL

I have google to find the code for PC to two Arduino a Nano. I will use MAX485 with USB TTL. So far I have the information how to wire plus 120ohm at the beginning and end of wire. I can’t find sample code for Nano and PC. Each Nano will have some leds and switches. I want to be about turn on leds from pc and hit the switch from Nano which pc will get 0 to become 1. Where can we find sample code for it?

Based on your previous posts, you don't want to use something like Modbus because it is too complicated.

The simplest solution would be to use two 'point to point' cables with full duplex communication. Each one needs its own USB/TTL converter. If the cables are short and you are running at slow baud rates then you don't need RS485 converters.

The Arduino receives/sends data using Serial.read() and Serial.println().
The PC program can be written in any language that allows serial communication, for example Python.

Mikb55,

Can you explain a little more about full duplex? My guess to uses two Max 485 for each Arduino Nano. where can we find a sample program or source code? What about the wiring diagram? Do we need 120 ohms for each max485? I would like to see a sample of how does it work with two max485 for each Arduino.

Reid

Start by plugging in a USB cable from your computer to a single Arduino and follow this Youtube tutorial.

You will be limited to the length of the USB cable, but that doesn't matter at the moment. Your first goal is to just to get communication working in both directions (full duplex).

To learn Python start with a tutorial such as this Learn Python - Full Course for Beginners [Tutorial] - YouTube
For an IDE there's the free 'community edition' of Pycharm.

Mikb55

I already done this pc to Arduino on usb cable. I was planning to use i2c but it will not work if more than 10 feet. I need 30 feet between pc and Arduino. The only thing I can think to use MAX485. I do have some MAX485 and usb to 485 converter. https://images.app.goo.gl/r36r1mAioLmgS6Pb6 See the picture. I thought I could give a try. But I couldn’t find the source code for it. I am using Lazarus (Delphi) program. If you have a better suggest or can we use i2c for long distance.

Reid

Are you able to communicate with the Arduino using Lazarus?

If so, you don't need any more code. The problem is now just a matter of using a 2 pairs of Max485 converters to turn your Tx and Rx TTL signals into Rs485 then back to TTL:
You need two circuits, one for Tx, the other for Rx. They both connect to a USB/TTL converter plugged into your computer.