ML999:
So I've wired it up, written a simple test sketch and...nothing happens. Tried swapping A and B over with no joy. I'm not even sure where to begin troubleshooting and if the problem is in the wiring or not - here is what I wrote:
The arduino is a mega.
Pin 18 goes to DI
Pin 7 goes to DE
3.3v goes to RE
GND goes to GND on shield
GND goes to GND of RS485 device
5v goes to VCC
/*-----( Import needed libraries )-----*/
//pin 7 DE -need to set high
//pin 18 DI- Serial1 TX Pin
/-----( Declare Constants and Pin Numbers )-----/
#define Pin13LED 13
#define DEpin 7
/-----( Declare Variables )-----/
byte dataframedown[13]={0x7f,0xf2,0xfa,0x01,0x00,0x00,0x49,0x55,0xfa,0xfb,0xfd,0x05,0xfc}; /
void setup() {
pinMode(Pin13LED, OUTPUT);
pinMode(DEpin, OUTPUT);
digitalWrite(DEpin,HIGH); //enable rs485 transmission on shield
// Start the software serial port, to another device
Serial1.begin(4800,SERIAL_8O1); // set the data rate & odd parity on Serial1 (pin 18)
for(int i=0;i<13;i++)
{
Serial1.write(dataframedown[i]); // Send byte stream to Remote device
delay (100);
}
Remove the delay()
for(int i=0;i<13;i++){
Serial1.write(dataframedown[i]);
}
Serial1.flush(); // this command will hang until all of the data is shifted out the UART
digitalWrite(DEpin,LOW); // release BUS
ML999:
}//--(end setup )---
void loop()
{
digitalWrite(Pin13LED, HIGH); // Show activity
delay(1000);
digitalWrite(Pin13LED, LOW); // Show activity
delay(1000);
}//--(end main loop )---
/-----( Declare User-written Functions )-----/
//NONE
//( THE END )**
I would start by changing your wiring a little, I would connect the rx (RO) to pin 19 of the MEGA, connect RE to GND. This will allow you to monitor the RS485 buss. everything that is transmitted on the buss, even your commands will show up. I would read the Serial1 UART and set that input out to the Serial monitor.
static unsigned long timeout=0; // an example how to delay without actually using delay()
void loop(){
char buf[10];
bool printed=false;
while(Serial1.available()){
sprintf(buf,"0x%02X ",Serial1.read());
Serial.print(buf);
printed=true;
}
if(printed) Serial.println();
if(millis()-timeout>1000) {
digitalWrite(13,!digitalRead(13)); // blink pin every second
timeout = millis(); // new timeout
}
}// end loop
Chuck.
p.s. ML999, if you use the quote button in you replies, your reply shows up in my unread message list. else I have to specifically reread all messages i have commented on to find your reply.