PC to USB TTL to Max485 to Arduino lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- microguy · 2020-12-11 03:54 I finally got the PC to USB TTL to Max485 to Arduino working now. But they are very slow to run it. I have 12 buttons. (six for off and six for on) with 6 LEDs on Arduino. Is there a way we can make this faster?  When I click the first button and the first LEDs come on. But I can't click the second button till the first LEDs finish light on then I can click the second one. Here is my code for Lazarus. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);begin  ser.SendString('2'); // button 2 should have 'on' hereend; procedure TForm1.Button3Click(Sender: TObject);begin  ser.SendString('3'); // button 3 should have 'off' hereend; procedure TForm1.Button4Click(Sender: TObject);begin  ser.SendString('4'); // button 4 should have 'on' hereend; procedure TForm1.Button5Click(Sender: TObject);begin  ser.SendString('5'); // button 5 should have 'off' hereend; procedure TForm1.Button6Click(Sender: TObject);begin  ser.SendString('6'); // button 4 should have 'on' hereend; Code for Arduino Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i int RE_DE = 2; void setup(){  pinMode(13, OUTPUT);  pinMode(3, OUTPUT);  pinMode(4, OUTPUT);  pinMode(5,OUTPUT);  pinMode(6, OUTPUT),  pinMode(7, OUTPUT); // Put Max485 in transmit mode so that Arduino can recieve message  pinMode(RE_DE, OUTPUT);  digitalWrite(RE_DE, LOW); // Start up serial connection  Serial.begin(9600);}void loop(){  if (Serial.available())    {    int state = Serial.parseInt();    if (state == 1)      {      digitalWrite(13, LOW);      Serial.println("Command completed LED 13 turned OFF");      }    if (state == 2)      {       digitalWrite(13, HIGH);      Serial.println("Command completed LED 13 turned ON");      }    if (state == 3)      {      digitalWrite(3, LOW);      Serial.println("Command completed LED 3 turned OFF");      }    if (state == 4)      {      digitalWrite(3, HIGH);      Serial.println("Command completed LED 3 turned ON");      }    if (state == 5)      {      digitalWrite(4, LOW);      Serial.println("Command completed LED 4 turned OFF");      }    if (state == 6)      {      digitalWrite(4, HIGH);      Serial.println("Command completed LED 4 turned ON");      }    if (state == 7)      {      digitalWrite(5, LOW);      Serial.println("Command completed LED 5 turned OFF");      }    if (state == 8)      {      digitalWrite(5, HIGH);      Serial.println("Command completed LED 5 turned ON");      }    if (state == 9)      {      digitalWrite(6, LOW);      Serial.println("Command completed LED 6 turned OFF");      }    if (state == 10)      {      digitalWrite(6, HIGH);      Serial.println("Command completed LED 6 turned ON");      }    if (state == 11)      {      digitalWrite(7, LOW);      Serial.println("Command completed LED 7 turned OFF");      }    if (state == 12)      {      digitalWrite(7, HIGH);      Serial.println("Command completed LED 7 turned ON");      }    }} Hope someone can help me to make this faster. I did change the speed from 9600 to 28800. It makes no difference. I want to fix this first before I can add servos and IR sensor on it. Also, I am not sure how to add the second and third Ardunio. How do we address each? I do know how to add wires to it.  Can someone give me idea on this? [Edited to add code tags - please see Using the Forums.] ---------------------------------------------------------------------- bd4kc · 2020-12-11 05:45 Before Serial.println, whether to set up a control RS485 receiving/send control PIN? digitalWrite(RE_DE, HIGH); Serial.println("Command completed LED 13 turned OFF"); digitalWrite(RE_DE, LOW); I don't know much about arduino, I just know a little bit about AVR MCUs. ---------------------------------------------------------------------- bd4kc · 2020-12-11 05:49 Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i void loop(){  if (Serial.available())    {    int state = Serial.parseInt();    if (state == 1)      {state =0;      digitalWrite(13, LOW);      Serial.println("Command completed LED 13 turned OFF");       }    if (state == 2)      {state =0;      digitalWrite(13, HIGH);      Serial.println("Command completed LED 13 turned ON");      }    if (state == 3)      {state =0;      digitalWrite(3, LOW);      Serial.println("Command completed LED 3 turned OFF");      }    if (state == 4)      {state =0;      digitalWrite(3, HIGH);      Serial.println("Command completed LED 3 turned ON");      }    if (state == 5)      {state =0;      digitalWrite(4, LOW);      Serial.println("Command completed LED 4 turned OFF");      }    if (state == 6)      {state =0;      digitalWrite(4, HIGH);      Serial.println("Command completed LED 4 turned ON");      }    if (state == 7)      {state =0;      digitalWrite(5, LOW);      Serial.println("Command completed LED 5 turned OFF");      }    if (state == 8)      {state =0;      digitalWrite(5, HIGH);      Serial.println("Command completed LED 5 turned ON");      }    if (state == 9)      {state =0;      digitalWrite(6, LOW);      Serial.println("Command completed LED 6 turned OFF");      }    if (state == 10)      {state =0;      digitalWrite(6, HIGH);      Serial.println("Command completed LED 6 turned ON");      }    if (state == 11)      {state =0;      digitalWrite(7, LOW);      Serial.println("Command completed LED 7 turned OFF");      }    if (state == 12)      {state =0;      digitalWrite(7, HIGH);      Serial.println("Command completed LED 7 turned ON");      }    } ---------------------------------------------------------------------- bd4kc · 2020-12-11 06:28 Or Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       digitalWrite(7, LOW);      Serial.println("Command completed LED 7 turned OFF");      }    if (state == 12)      {       digitalWrite(7, HIGH);      Serial.println("Command completed LED 7 turned ON");      }state =0;    } ---------------------------------------------------------------------- Laksen · 2020-12-11 11:52 It's serial.parseInt that waits until either a non digit char is read or a timeout Just try using Ser.SendString('2'+#13#10); instead and it should be blazing fast ---------------------------------------------------------------------- microguy · 2020-12-11 19:14 Laksen, Can you explain a little more?  Where do we put Ser.SendString('2'+#13#10); Should we change serial.parseInt to something else? ---------------------------------------------------------------------- Laksen · 2020-12-11 19:37 In the pascal program. Instead of ser.SendString('2'); And the same for the others ---------------------------------------------------------------------- microguy · 2020-12-11 21:37 Got it working fast.  Many thanks.  Can you tell me what is #13 and #10?   Also, do you know how I can send the second and third Arduino? Also, I need to figure out how to use IR sensors and send data to Lazarus. I was thinking to use Tshape with different colors for each IR Sensors. Also, I would like to use several servos and use the Control Bar from Lazarus to control Servos. ---------------------------------------------------------------------- trev · 2020-12-11 21:55 Quote from: microguy on December 11, 2020, 10:37:36 pmCan you tell me what is #13 and #10?  Carriage return + Line feed ! ---------------------------------------------------------------------- microguy · 2020-12-13 03:08 Can someone help me how to write the code for second and third Arduino? Also servos? I Want to know two buttons which one for left and one for right or one for up and one for down servos. ---------------------------------------------------------------------- microguy · 2021-02-06 20:56 I got the servos working now with PCS9685. But I still could not figure out how to get a second or third Arduino working. I understand we need to put the address on each Arduino. But still need help with it. ---------------------------------------------------------------------- MarkMLl · 2021-02-07 10:27 You need to read up on multidrop communications. This sort of thing used to be used very heavily by commercial (i.e. mainframe etc.) data communications and is still used heavily in industry, although there is a regrettable tendency these days to stick Ethernet in everything and hope it works. Apart from that, you're the one writing the Arduino code, you're the one writing the PC code, and unless you use a library at both ends which is guaranteed to implement the same protocol you're the one handling overall system design including the bytes that go backwards and forwards on the RS485 connection. Hence, I'm very sorry but you're in charge and it's your problem. MarkMLl ---------------------------------------------------------------------- dseligo · 2021-02-07 12:36 Quote from: microguy on February 06, 2021, 09:56:49 pmI got the servos working now with PCS9685. But I still could not figure out how to get a second or third Arduino working. I understand we need to put the address on each Arduino. But still need help with it. How are they all connected together? Do all Arduino's receive same data? If all receive same data then you could send something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ser.SendString('A2'); // button 2 on "A" Arduinoser.SendString('B2'); // button 2 on "B" Arduinoser.SendString('C2'); // button 2 on "C" Arduino or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ser.SendString('12'); // button 2 on "1st" Arduinoser.SendString('22'); // button 2 on "2nd" Arduinoser.SendString('32'); // button 2 on "3rd" Arduino And you have to parse results in Arduino. Example bellow is if you address them with numbers. If you address them with letters, you'll have to extract letter first and check if it belong to current Arduino. First Arduino: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     int state = Serial.parseInt();...    if (state == 12)      {      digitalWrite(13, HIGH);      Serial.println("Command completed LED 13 turned ON");      }  Second Arduino: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     int state = Serial.parseInt();...    if (state == 22)      {      digitalWrite(13, HIGH);      Serial.println("Command completed LED 13 turned ON");      }  And so on.