Hello,
I need some help. I need to connect my arduino to PC using rs485. I figured I could use the MAX485 IC from Maxim. However, I am not able to communicate with the arduino through serial monitor. I will be powering the arduino board with an external PS and does not need to use the USB-port. Therefore I choose to connect the RX and TX from the MAX485 directly to Pin 0 and 1 respectively. As far as I have understood, I do not need to use extra libraries since I am going to use Pin 0 and 1 as RX-TX, and therefore I do not have to do any changes to the code I wrote for serial communication with USB?
On the computer side I am using a simple USB-2-rs485 converter.
I have connected my arduino to the MAX485 chip using this exact circuit attached, which I found online:
http://www.extremadura-web.es/Blog/2013/04/19/arduino-uno-modbus-max485/
I know I should terminate the ends, but right now I am working with a 3 meter long cable just for testing…
Is it even feasible to get this working with the MAX485 and a usb-2-rs485 converter?
I am also attaching my code, which works fine when I use it through USB…
PS: This is my first post, so go easy on me
#include <TimerOne.h>
unsigned char channel_1 = 4; // Output to Opto Triac pin, channel 1
unsigned char CH1;
unsigned char CHANNEL_SELECT;
unsigned char i=0;
unsigned char clock_tick; // variable for Timer1
unsigned int delay_time = 50;
unsigned char low = 75;
unsigned char high = 5;
unsigned char off = 95;
int ByteReceived;
void setup() {
pinMode(channel_1, OUTPUT);// Set AC Load pin as output
attachInterrupt(1, zero_crosss_int, RISING);
Timer1.initialize(100); // set a timer of length 100 microseconds;
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
{
Serial.begin(9600);
Serial.println("--- Start Serial Monitor SEND_RCVE ---");
Serial.println(" Type in Box above, . ");
Serial.println("(Decimal)(Hex)(Character)");
Serial.println();
}
}
void timerIsr()
{
clock_tick++;
if (CH1==clock_tick)
{
digitalWrite(channel_1, HIGH); // triac firing
delayMicroseconds(5); // triac On propogation delay
digitalWrite(channel_1, LOW); // triac Off
}
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Every zerocrossing interrupt: For 50Hz (1/2 Cycle) => 10ms ; For 60Hz (1/2 Cycle) => 8.33ms
// 10ms=10000us , 8.33ms=8330us
clock_tick=0;
}
void loop() {
if (Serial.available() > 0)
{
ByteReceived = Serial.read();
Serial.print(ByteReceived);
Serial.print(" ");
Serial.print(ByteReceived, HEX);
Serial.print(" ");
Serial.print(char(ByteReceived));
if(ByteReceived == '0') // Single Quote! This is a character.
{
i = 85;
CH1 = i;
Serial.print(" 10 % ");
}
....
Serial.println(); // End the line
// END Serial Available
}
}