Got a little question about the RS485 Lib. I used this one from Nick Gammon ( http://www.gammon.com.au/forum/?id=11428 )
I used this lib to make my own houseautomation with an arduinoNanoV3 for Master.
The Slaves are build with Atmega und Attiny84. The Communication made with NewSoftSerial under 0023
The Master Communication worked fine with NewSoftSerial an compiled under 0023.
So yesterday i started to work with 1.0.1, i read on the main site of arduiniana who developed the newsoftserial under 00xx that the SOftwareSerial wich included on 1.0.1 is the same way. I only have to chance the NewSoftSerial to SoftwareSerial.
It worked on the slaves with the 1.0.1. On the master (with the abolutly same code only the changes of NewSoftSerial =>SoftwareSerial) it wont worked i tried many times with also with checking the buffer over hardware serial with an Terminalprogramm. But it wont work.
Do you know about Problems with you rs485 Softserial and arduino 1.0.1.
With the Aruino IDE 0023 worked it completly
WIth the Arduino 1.0.1 it wont work. Bothe IDEs compiled this code without Failure.
The Master Code (wich i have the problems)
These Verison worked with 0023
I only change for Working with 1.0.1 The WConstans.h => adruino.h
and the NewSoftSerial => to Software Serial (also the beginning of th class)
#include <nokia_3310_lcd.h>
#include "WConstants.h"
#include <NewSoftSerial.h>
#include "RS485_protocol.h"
#define ENABLE_PIN 4 // Enable Pin (High= Senden aktiv LOW empsfanen aktiv
int RINT1,RINT2,RINT3,Wert=0;
boolean links,hoch,rechts,runter,cbut,clock,lastclock=false;
boolean L1,L2,L3=true;
boolean lrechts=false;
boolean Send=false;
unsigned long pm1;
unsigned long pm2;
byte ref1=100;
byte ref2=33;
byte State,page,line,ebene,ebeneold=0;
byte Adresse=1;
byte AdresseSlave=0;
byte sndbuffer [4]; // Buffer für Daten max 20 Byte
void fWrite (const byte what) // Handler für RS485 Lib
{
rs485.print (what);
}
int fAvailable ()
{
return rs485.available ();
}
int fRead ()
{
return rs485.read ();
}
Nokia_3310_lcd lcd=Nokia_3310_lcd();
NewSoftSerial rs485 (2, 3); // Initalisierung SoftSerial für RS485 (receive pin, transmit pin)
void setup (){
lcd.LCD_3310_init(); //Display Intialiseiern
lcd.LCD_3310_clear(); // Display löschen
// Serial.begin(9600);
rs485.begin(9600);
pinMode (ENABLE_PIN, OUTPUT); // Pin als Ausgang setzten
}
byte msg[4];
void loop(){
if (millis()-pm2 > ref2){
pm2=millis();
lcd.LCD_3310_clear(); // Display löschen
}
if (millis()-pm1 > ref1){
pm1=millis();
clock = !clock;
}
if (clock==true){
key_in();
key();
}
if(rechts==true&&lrechts==false){
if (page==0)
page=line+1;
lrechts=true;
line=0;
}
if (links==true){
page=0;
}
switch (page){
case 0:
Menu();
break;
case 1:
Seite1();
break;
case 2:
Seite2();
break;
case 3:
Seite3();
break;
case 4:
Seite4();
break;
case 5:
Seite5();
break;
case 6:
Seite6();
break;
}
if (line <=0){
line=0;
}
if (line >=5){
line=5;
}
if(Send==true){ // Senden der Anforderung
// Buffer für Daten max 20 Byte
msg[0]=AdresseSlave; // Adresse vom Slave
msg[1]=0xAA; // Anfoderung Daten Senden BIN 1010101=0xf
digitalWrite(ENABLE_PIN,HIGH); // Treiber Aktivieren
sendMsg (fWrite, msg, sizeof msg); // Daten Senden
digitalWrite(ENABLE_PIN,LOW); // Treiber deaktiviern Empfänger akvivieren
Send=false;
}
}
/* byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf) - 1,50);
if (received)
{
if (buf [0] != Adresse) // Ist das meine Adresse
return; // not my device
RINT1=(buf[1]<<8)|(buf[2]); // Zusammensetzten des Empfangenen Bytes
RINT2=(buf[3]<<8)|(buf[4]);
RINT3=(buf[5]<<8)|(buf[6]);
}
*/
void key(){
if (State==1 && links==false){ //links
links=true;
if (ebene>=1){
ebene=ebene--;
}
}
if (State==3 && rechts==false){ //rechts
rechts=true;
if (ebene<=1){
ebene=ebene++;
}
}
if (State==2 && hoch==false){ // Hoch
line=line--;
hoch=true;
}
if (State==4 && runter==false){ // Runter
line=line++;
runter=true;
}
if (State==5 && cbut==false){
if (page==2){
AdresseSlave=1;
if (line==0){
L1=!L1;
msg[2]=12; // Ausgang am Slave
msg[3]=L1; // Status des Ausgang
Send=true;
}
if (line==1){
L2=!L2;
msg[2]=11; // Ausgang am Slave
msg[3]=L2; // Status des Ausgangs
Send=true;
}
}
if (page==3){
AdresseSlave=2;
if (line==0){
L3=!L3;
msg[2]=12; // Ausgang am Slave
msg[3]=L3; // Status des Ausgangs
Send=true;
}
}
cbut=true;
}
if (State==0){
links=false;
hoch=false;
rechts=false;
runter=false;
cbut=false;
lrechts=false;
}
}
void key_in(){
Wert=analogRead(A0);
if (Wert<20)
State=1; //links //Links
if (Wert<550 && Wert>475)
State=2; //oben //Oben
if (Wert<780 && Wert>650)
State=3; //rechts //Rechts
if (Wert<370 && Wert>300)
State=4; //unten // Unten
if (Wert>980)
State=0; // nichts
if (Wert<200 && Wert>100)
State=5; // Gedrückt
}
Second Tab:
void Menu(){
lcd.LCD_3310_write_string(0,line,">",MENU_NORMAL);
lcd.LCD_3310_write_string(6,0,"Master",MENU_NORMAL);
lcd.LCD_3310_write_string(6,1,"Slave1",MENU_NORMAL);
lcd.LCD_3310_write_string(6,2,"Slave2",MENU_NORMAL);
lcd.LCD_3310_write_string(6,3,"Seite 4",MENU_NORMAL);
lcd.LCD_3310_write_string(6,4,"Seite 5",MENU_NORMAL);
lcd.LCD_3310_write_string(6,5,"Seite 6",MENU_NORMAL);
}
void Seite1(){
lcd.LCD_3310_write_string(0,0,"RS485 Test",MENU_NORMAL);
lcd.LCD_3310_write_string(0,1,"Master bin ",MENU_NORMAL);
lcd.LCD_3310_write_string(0,2,"ICH ICH ICH",MENU_NORMAL);
}
void Seite2(){
lcd.LCD_3310_write_string(0,line,">",MENU_NORMAL);
lcd.LCD_3310_write_string(6,0,"LED rt",MENU_NORMAL);
if (L1==true)
lcd.LCD_3310_write_string(50,0,"Ein",MENU_HIGHLIGHT);
else
lcd.LCD_3310_write_string(50,0,"Aus",MENU_NORMAL);
lcd.LCD_3310_write_string(6,1,"LED gn",MENU_NORMAL);
if (L2==true)
lcd.LCD_3310_write_string(50,1,"Ein",MENU_HIGHLIGHT);
else
lcd.LCD_3310_write_string(50,1,"Aus",MENU_NORMAL);
lcd.LCD_3310_write_string(6,5," Slave 1 ",MENU_NORMAL);
}
void Seite3(){
lcd.LCD_3310_write_string(0,line,">",MENU_NORMAL);
lcd.LCD_3310_write_string(6,0,"LED rt",MENU_NORMAL);
if (L3==true)
lcd.LCD_3310_write_string(50,0,"Ein",MENU_HIGHLIGHT);
else
lcd.LCD_3310_write_string(50,0,"Aus",MENU_NORMAL);
lcd.LCD_3310_write_string(6,5," Slave 2 ",MENU_NORMAL);
}
I solved the problem after testing testing testing testing testing testing testing. Only change the RS485.print => RS485.write
Glad we could help
Rob