tag:blogger.com,1999:blog-5229899856062584712.post7950686447263744564..comments2023-03-21T01:44:52.407-07:00Comments on Tinkering with Electronics...: Arduino and RS485 (ENGLISH VERSION)Igorhttp://www.blogger.com/profile/07332255486737492708noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-5229899856062584712.post-50932972520496350972016-12-03T09:54:25.083-08:002016-12-03T09:54:25.083-08:00Hi, great tutaorial, thanks.
Do you know what is t...Hi, great tutaorial, thanks.<br />Do you know what is the latency between the button press and the led on ?<br />Anonymoushttps://www.blogger.com/profile/07555415473428140279noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-66578611984357601432015-12-05T15:08:15.151-08:002015-12-05T15:08:15.151-08:00Just delete the "BYTE" thing. Arduino no...Just delete the "BYTE" thing. Arduino nowadays sends the serial data byte like so if you say BYTE is like a double declaration.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-2882969943169530572015-12-05T14:47:50.698-08:002015-12-05T14:47:50.698-08:00Hello sir,
I'm new in arduino and rs485. I ha...Hello sir, <br />I'm new in arduino and rs485. I have a Siedle Automation System in my home and I want to make an upgrade to it. Siedle System has a card reader and a central processing unit that uses RS485 protocol at 9600 baud rate to comunicate with the multiple card readers. I used your slave code to get in the bus and read data. I've seen different reads at different cards, wich is what I want to do, making an if function to determine wich card is wich and to actuate rellays in case of some of the cards. <br /><br />This is the log i recive from the serial reading: <br /><br />Am primit codul:<br />A8 3 6 2 40 2D 11 82 3 6 checksum:<br />11522<br /><b>01683152644517130363831229</b>Am primit byte-ul de start: 0<br />Am primit bit:?3<br /><br />That long number is the number i need to pull out for the if thing, but I can't undestand where it comes from. <br />Here is the code: (what I've changed from )<br /> while (Serial.available() > 0){<br /> <br /> byte_receive=Serial.read();<br /> if (byte_receive==00){<br /> Serial.print("Am primit byte-ul de start:");<br /> Serial.print("\t");<br /> Serial.println(byte_receive);<br /> state=1;<br /> checksum_trace=0;<br /> checksum=0;<br /> trace_OK=0;<br /> address=0;<br /> data_received=0;<br /> cont1=1;<br /> }else if (state==1 && cont1<=12){<br /> data[cont1-1]=byte_receive;<br /> checksum=checksum+byte_receive;<br /> cont1=cont1+1;<br /> }else if (state==1 && cont1==13){<br /> checksum_trace=byte_receive<<8;<br /> cont1=cont1+1;<br /> //Serial.print("Primer Byte Checksum"); <br /> //Serial.print(checksum_trace,HEX);<br /> }else if (state==1 && cont1==14){<br /> checksum_trace=checksum_trace+byte_receive;<br /> cont1=cont1+1;<br /> state=0;<br /> Serial.print("Am primit bit:?");<br /> Serial.println(byte_receive,HEX);<br /> Serial.println("Am primit codul:");<br /> //Serial.print("Checksum Trace= ");<br /> //Serial.println(checksum_trace,HEX);<br /> //Serial.print("Checksum= ");<br /> //Serial.println(checksum,HEX);<br /> //Serial.println(checksum,DEC);<br /> Serial.println("Datele= ");<br /> Serial.print(data[0], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[1], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[2], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[3], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[4], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[5], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[6], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[7], HEX);<br /> Serial.print("\t");<br /> Serial.print(data[8], HEX); <br /> Serial.print("\t");<br /> Serial.print(data[9], HEX); <br /> Serial.print("\t"); <br /><br /><br />Thank you very much. <br /><br />Iulianhttp://copertalumii.blogspot.ro/noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-56690536466629551252015-09-11T11:03:00.655-07:002015-09-11T11:03:00.655-07:00Hola Igor he estado viendo tus tutoriales el de in...Hola Igor he estado viendo tus tutoriales el de ingles y español, quiero hacer un sistemas de bus de datos a dos hilos pero mi esquema va Arduino-Rs485-sensor como hago que desde el arduino pida el dato del sensor. 2. corri tu codigo y me marca este error.<br /><br />byte, byte, byte, byte, byte, byte, byte)':<br />sketch_sep11a:185: error: 'BYTE' was not declared in this scope<br /><br />Desde Arduino 1.0, la palabra clave 'BYTE' ya no está soportada en <br />Serial.print(var, BYTE). Por favor utiliza Serial.write() en su lugar.<br /><br />me podrias ayudar¿ GraciasAnonymoushttps://www.blogger.com/profile/16009874666589190554noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-68131701478354014412015-03-06T06:45:28.831-08:002015-03-06T06:45:28.831-08:00Hi, I'm having some trouble understanding the ...Hi, I'm having some trouble understanding the two following lines of code.<br /><br />"UCSR0A=UCSR0A |(1 << TXC0);" as well as "while (!(UCSR0A & (1 << TXC0)));"<br /><br />I have recently finished a project using the MAX485 chip using Arduinos as 1 master and 3 slaves transmitting about 20 metres. I ran into an issue where I was required to add a 50ms delay between pulling the transmit pin high and sending the serial data (in my case chars). If the delay was any shorter then the slaves would only read gibberish.<br />There was also the issue that when two of the slaves were transmitting at the same time, the master would also just see gibberish. Although I'm not sure if that was a timing issue or something else.<br />Any insight you could give me would be much appreciated.<br />Thanks :)Lacanauhttps://www.blogger.com/profile/03628967269663298265noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-29974979216075706932014-11-13T08:25:21.445-08:002014-11-13T08:25:21.445-08:00Is it possible to have the master turn on a light ...Is it possible to have the master turn on a light at the slave. The slave to turn on a light at the master. And a button at the master to turn off both lights?<br />Thanks.SetMonkey13https://www.blogger.com/profile/09709898314790961715noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-7685909427194072742013-09-05T23:58:23.087-07:002013-09-05T23:58:23.087-07:00Giangi,
Corrected sendNAK should have been as belo...Giangi,<br />Corrected sendNAK should have been as below (because NAK = 0x15 = 21:<br /><br />void sendNAK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br />sendACK_NAK(21, address1, address2, data_type, code1, code2, Sign, data1, data2, data3, data4);<br />}<br />MAPhttps://www.blogger.com/profile/16768362135297652202noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-45634128036995211402013-08-22T12:25:54.429-07:002013-08-22T12:25:54.429-07:00Yes it´s possible.
Regards,
IgorYes it´s possible.<br /><br />Regards,<br /><br />IgorIgorhttps://www.blogger.com/profile/07332255486737492708noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-24882126467644580032013-08-22T10:27:50.613-07:002013-08-22T10:27:50.613-07:00Noob question:
I want to connect several sensors ...Noob question:<br /><br />I want to connect several sensors to an Arduino, but each sensor will be far from it, like 20 to 30 meters. Is it possible to send the sensor data (ultrasound/temp) via RS485?<br /><br />Thanks,<br /><br />AlvaroAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-12741059381248741882013-05-09T16:25:06.883-07:002013-05-09T16:25:06.883-07:00Hello Well done for this nice job ! ! !
I would l...Hello Well done for this nice job ! ! !<br /><br />I would like to ask if it is possibly to make a library so less code need to use in the IDE.<br /><br />Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-53959165513577362102013-01-27T05:49:08.428-08:002013-01-27T05:49:08.428-08:00Hello, I'd like to know, which are the parts o...Hello, I'd like to know, which are the parts of the whole message that I can use to communicate the commands?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-70653853071282640252012-08-04T06:24:30.357-07:002012-08-04T06:24:30.357-07:00Hello, thanks for your post.
I've tried to imp...Hello, thanks for your post.<br />I've tried to implement the same circuit, but I'm facing a problem to use the Arduino as USB->Serial converter. I just receive datas in the PC, but I'm not able to send datas from it.<br />Could you help me?<br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-48654119674849349892012-05-29T11:50:05.807-07:002012-05-29T11:50:05.807-07:00Hi,
Could you please post a schematic of how you ...Hi, <br />Could you please post a schematic of how you wired the led and the pushbutton?<br /><br />Thank's,<br />CristianAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-30010769281735881122011-10-09T14:36:03.840-07:002011-10-09T14:36:03.840-07:00Hi,
can send me a schematic to build this? Where ...Hi, <br />can send me a schematic to build this? Where to put the resistor and where the jumper?<br /><br />Thank You <br /><br />Andreasbeerwinkel77https://www.blogger.com/profile/16396576488866794780noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-31355552476929329822011-04-29T05:46:00.452-07:002011-04-29T05:46:00.452-07:00Hi,
I'm wondering if there won't be any p...Hi,<br /><br />I'm wondering if there won't be any problems with addresses if I set master to 01 and slaves as u wrote 01 and 02. Shouldn't be for ex. master 01, slave_1 02, and slave_2 03 ??<br /><br />I hope it isn't a stupid question - I'm just starting with it<br /><br />cheers.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-68217245504488721232011-01-20T14:19:23.280-08:002011-01-20T14:19:23.280-08:00Good points Giangi!! Please feel free to send me y...Good points Giangi!! Please feel free to send me your improvements and I can publish them here.<br /><br />Thanks!<br /><br />;)Igorhttps://www.blogger.com/profile/07332255486737492708noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-74935112910741447622011-01-19T07:46:49.903-08:002011-01-19T07:46:49.903-08:00Igor I think there is a bug in the original sendNA...Igor I think there is a bug in the original sendNAK function.<br />Should the row<br />checksum_ACK=address1+address2+6+data_type+code1+code2+Sign+data1+data2+data3+data4+3;<br />be corrected in <br />checksum_ACK=address1+address2+21+data_type+code1+code2+Sign+data1+data2+data3+data4+3;<br />?<br />Notice the 21 value (0x15h) instead of 6 because you wrote ENQ, ACK or NAK (0x05h, 0x06h y 0x15h).<br /><br />In this case the code is much simplier because you can merge the sendMSG code too:<br /><br />void sendMSG(byte type, byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br /><br /> unsigned int checksum_ACK;<br /> checksum_ACK=address1+address2+type+data_type+code1+code2+Sign+data1+data2+data3+data4+3;<br /><br /> UCSR0A=UCSR0A |(1 << TXC0);<br /><br /> digitalWrite(pinCONTROL,HIGH);<br /> delay(1);<br /><br /> Serial.print(0,BYTE);<br /> Serial.print(address1,BYTE);<br /> Serial.print(address2,BYTE);<br /> Serial.print(type,BYTE);<br /> Serial.print(data_type,BYTE);<br /> Serial.print(code1,BYTE);<br /> Serial.print(code2,BYTE);<br /> Serial.print(Sign,BYTE);<br /> Serial.print(data1,BYTE);<br /> Serial.print(data2,BYTE);<br /> Serial.print(data3,BYTE);<br /> Serial.print(data4,BYTE); <br /> Serial.print(3,BYTE);<br /> Serial.print(((checksum_ACK>>8)&255),BYTE);<br /> Serial.print(((checksum_ACK)&255),BYTE);<br /> while (!(UCSR0A & (1 << TXC0)));<br /> digitalWrite(pinCONTROL,LOW);<br />}<br /><br />void sendACK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br /> sendMSG(6, address1, address2, data_type, code1, code2, Sign, data1, data2, data3, data4);<br />}<br /><br /><br />void sendNAK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br /> sendMSG(15, address1, address2, data_type, code1, code2, Sign, data1, data2, data3, data4);<br />}Giangi72https://www.blogger.com/profile/02965270528575846224noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-53761865512689671942011-01-19T03:15:52.155-08:002011-01-19T03:15:52.155-08:00And this one too:
byte hex2num(byte x){
byte res...And this one too:<br /><br /><br />byte hex2num(byte x){<br />byte result;<br /><br />if (x>=48 && x<=57){ //numbers 0-9<br /> result=x-48; <br />}else if (x>=65 && x<=70){ //A-F<br /> result=x-55; //A=10, B=11, …,F=15<br />}<br />return result; <br />}Giangi72https://www.blogger.com/profile/02965270528575846224noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-37273547307298907822011-01-19T03:15:19.993-08:002011-01-19T03:15:19.993-08:00Hi Igor,
Thanks for your work.
I semplified your ...Hi Igor,<br />Thanks for your work.<br /><br />I semplified your code, it is easier to mantain it too:<br /><br />void sendACK_NAK(byte type,byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br /><br />unsigned int checksum_ACK;<br />checksum_ACK=address1+address2+6+data_type+code1+code2+Sign+data1+data2+data3+data4+3;<br /><br />UCSR0A=UCSR0A |(1 << TXC0);<br /><br />digitalWrite(pinCONTROL,HIGH);<br />delay(1);<br /><br />Serial.print(0,BYTE);<br />Serial.print(address1,BYTE);<br />Serial.print(address2,BYTE);<br />Serial.print(type,BYTE);<br />Serial.print(data_type,BYTE);<br />Serial.print(code1,BYTE);<br />Serial.print(code2,BYTE);<br />Serial.print(Sign,BYTE);<br />Serial.print(data1,BYTE);<br />Serial.print(data2,BYTE);<br />Serial.print(data3,BYTE);<br />Serial.print(data4,BYTE); <br />Serial.print(3,BYTE);<br />Serial.print(((checksum_ACK>>8)&255),BYTE);<br />Serial.print(((checksum_ACK)&255),BYTE);<br />while (!(UCSR0A & (1 << TXC0)));<br />digitalWrite(pinCONTROL,LOW);<br />}<br /><br />void sendACK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br /> sendACK_NAK(6, address1, address2, data_type, code1, code2, Sign, data1, data2, data3, data4);<br />}<br /><br /><br />void sendNAK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4){<br />sendACK_NAK(15, address1, address2, data_type, code1, code2, Sign, data1, data2, data3, data4);<br />}Giangi72https://www.blogger.com/profile/02965270528575846224noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-81885683556299552972010-09-16T07:28:28.536-07:002010-09-16T07:28:28.536-07:00Hi Floris,
Of course you can. It´s the designer wh...Hi Floris,<br />Of course you can. It´s the designer who decides how the protocol works. It´s 100% open.<br />The RS485 only defines the phisical layer.<br /><br />Cheers!!<br /><br /><br />IgorIgorhttps://www.blogger.com/profile/07332255486737492708noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-56600036231749002822010-09-16T03:57:25.132-07:002010-09-16T03:57:25.132-07:00Nice tutorial!
question:
is it possible to sent d...Nice tutorial!<br /><br />question:<br />is it possible to sent data from the slave to the master in the ACK (in the byte 9 .. 12)?<br /><br />Floris at deboktor dot nlFlorishttps://www.blogger.com/profile/07933756966876021457noreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-27380170948065388882010-09-01T06:49:18.504-07:002010-09-01T06:49:18.504-07:00This is great, I've been looking for this for ...This is great, I've been looking for this for a while! Good detailed explination. <br /><br />Thanks from NL<br />RobAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-375061661122396892010-05-13T14:11:38.094-07:002010-05-13T14:11:38.094-07:00Hi,
Please, find below the pin out of the MAX485 ...Hi,<br /><br />Please, find below the pin out of the MAX485 (DIP-8)<br /><br />PIN-OUT MAX485 --> Arduino<br />1 -> RO (Receiver Output) to pin 0 (Rx)<br />2 -> Receive enable to a digital input (ej: pin2)<br />3 -> Driver enable to a digital (ej:pin2)<br />4 -> DI (Driver In) to pin 1 (Tx)<br />5 -> GND to gnd of the arduino<br />6 -> SIGNAL A (bus RS-485)<br />7 -> SIGNAL B (bus RS-485)<br />8 -> Vcc to 5 voltios of the arduino<br /><br /><br /><br />Regards,<br /><br /><br /><br />IgorIgorhttp://real2electronics.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-5229899856062584712.post-15574270866506239472010-01-16T03:28:50.670-08:002010-01-16T03:28:50.670-08:00This is just as a note for other people:
It took ...This is just as a note for other people:<br /><br />It took me a while to realize that you need to connect the write enable and read enable lines to the digital pin 2 on the microcontroller.Anonymousnoreply@blogger.com