Communicate with Pellet burner via rs232

Hi
This is my first “large” project, and I really need some advice.

I am working on a project where i want to communicate with my pellet burner via serial rs232.
The burnet needs a question before it answers what the boilertemperature, smoketemperature and light is.
After that i want the answer printet on a lcd.

My setup:
- Arduino Ethernet
- ttl-rs232 converter
- LCD 1602

String to send:
“Z000000Z” //what is the current status

I have tried with a serial terminal program “Coolterm” to send the string and i got a string of data return witch is good.

String recieved:
" 17 36 682 44 81 208 57 510687 12142 0 68 0 2260 -1 229 163 5 3."

I tried to write some code for my arduino so it can do the work and print the status on a ldc.
But until now without succes

My code so far:

#include <LiquidCrystal.h>
String inputString = "";         // a string to hold incoming data
String temp = "";
String smoket = "";
String light = "";
boolean stringComplete = false;  // whether the string is complete
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int switchpin = 8;
int val1 = 0;

//Set delay system
  unsigned long previousMillis = 0;        // will store last time LED was updated
  // constants won't change :
  const long interval = 10000;


//Specialcharacters
  byte oe[8] = {
  B00000,
  B00000,
  B01110,
  B10011,
  B10101,
  B11001,
  B01110,
};
 byte pil[8] = {
  B00000,
  B00100,
  B00010,
  B11111,
  B00010,
  B00100,
  B00000,
};

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  
  
  lcd.begin(16, 2);
  lcd.print("PelletBoiler");
  delay(3000);
  lcd.clear();
  
  establishContact();  // send a byte to establish contact until receiver responds
    
    //Specialcharacter
  lcd.createChar(0, oe);
  lcd.createChar(1, pil);

}
  
void loop() {
 
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;
  
      
}
  

  serialEvent(); //call the function
  
  // print the string when a newline arrives:
  if (stringComplete) {
    inputString.replace("  ", "");
        

//Temperatur
    temp = inputString;
    temp = temp.substring(20, temp.length() - 78);
    lcd.setCursor(0, 0);
    lcd.print("Temp");
    lcd.setCursor(5, 0);
    lcd.print(temp);
    lcd.print((char)223);  //temperature celsius sign
    
//Rog temperatur    
    smoket = inputString;
    smoket = smoket.substring(22, smoket.length() - 78);
    lcd.setCursor(9, 0);
    lcd.print("R");lcd.write(byte(0));lcd.print("g");
    lcd.print(smoket);
    lcd.print((char)223);  //temperature celsius sign
    
//lys    
    light = inputString;
    light = light.substring(22, light.length() - 78);
    lcd.setCursor(0, 1);
    lcd.print("Lys");
    lcd.print(light);
    
    inputString = "";
    stringComplete = false;
  }
}
  

void serialEvent() {
  
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;

        if (inChar == '.') {
        stringComplete = true;
        
    }
 }
}


{
void establishContact() {
  while (Serial.available() <= 0) {
           Serial.write(0X5A);
           Serial.write(0X30);
           Serial.write(0X30); 
           Serial.write(0X30); 
           Serial.write(0X30); 
           Serial.write(0X30); 
           Serial.write(0X30);
           Serial.write(0X5A);   // send request
    delay(300);
}

I also tried to connect the Coolterm (pretending to be the pellet burner) to the arduino via rs232.
Here i can monitor that the arduino sends the string “Z000000Z” and i can return the long string like the burner does.
This works perfekt and the arduino prints the numbers to the lcd.

But it does not work when the arduino i connected to the Burner.

Can someone help me :slight_smile:

Rasmus[/code]

So you have the burner connected to hardware serial (pins 0 and 1)? You also have hardware serial connected to the PC (through the on board TTL to USB converter on most Arduinos). You may have to switch the burner to a different serial port. Only one device can be connected to a serial port at a time. If your Arduino has only one serial port (Uno) you can set up a software serial port. The IDE comes with the Software Serial library and there are others available.

Hi

Sorry for the delay..

Yes it´s right that the uno only have one port.
The way i do it is that i unplug the serial port and program the board with a ttl-USB converter. When the board is updated i put on the serial board and then the communication works.

The only thing that does not work is the code. :frowning:

As mentioned i´ve tried to connect the serial board to a serial terminal program "Coolterm" on another pc.
There i can see that the arduino sends data and it also recieve data wich preints directly on the Lcd display..

But when the arduino is connected to the pellet burner it doesn´t work...

Any suggestions?

I have 2 suggestions. First is to use a software serial port for the burner so that you can get debug information from your sketch while it is running via hardware serial. And that does away with the potential hardware conflict with the hardware serial. Second is to look at Robin2’s serial input basics to see how to do non blocking serial communication with null terminated character strings (not Strings).

I never like it when people use SoftwareSerial for the real product jsut to have serial to debug. Yes, it's kind of an easy option be it gives a lot of questions around SoftwareSerial...

I once saw a simple solution to use a second Arduino connected via I2C (but SPI should also work) to do the work. Can't find it now but it's really really simple to to. That way you don't wast the Hardware Serial in the finished product :slight_smile:

Why not just connect the software serial to an FTDI Basic and use that for debug statements?

Course, you then have to connect to the hardware serial to download code again ...

I would add to what @groundfungus has to say that you will probably make life a great deal easier if you invest in an Arduino with at least one spare Hardware Serial port - such as a Mega or a Micro.

I would also suggest that you make the simplest possible Arduino program for initial tests with the burner and especially leave all the LCD stuff until after you know how to do the other parts. It will be much easier to get help here with a simple program and without the confusion of LCD stuff.

...R
Planning and Implementing a Program

"with at least one spare Hardware Serial port - such as a" '1284P based board also.
I offer '1284P boards in several different form factors.
http://www.crossroadsfencing.com/BobuinoRev17/index.html
This one is Uno-like. '1284P has dual hardware serial ports, 16K SRAM (twice that of the Mega), 128K flash, 4K EEPROM, just a nice chip.

For debugging a Mega can be nice indeed. But for a final product it seems a bit overkill. But yeah, you can switch then :slight_smile:

But like the second Arduino or a Serial-USB converter to a SoftwareSerial for debugging better :slight_smile:

Thanks for all your expertice..

I will soon buy a Arduino Mega and try debug.