Robin2
September 4, 2017, 5:02pm
21
roosterqmoney:
how does hardware serial work much much better? Is it faster? Is it possible to have errors using software?
As its name suggests it uses special hardware on the Atmega 328 chip to receive each character without using up any microprocessor clock cycles. And it can work at much higher baud rates. SoftwareSerial all has to be done by the microprocessor code. SoftwareSerial is like handwriting compared to a high speed laser printer.
can you give me an example how I would send the value 1024 to an arduino that uses the code from the cookbook. that is the piece I am missing to fully understand that method of serial communication.
I don't fully understand this statement
"You should also send a linefeed character with Serial.println(); at the end of your message so the receiving Arduino knows that it is the end of the message."
what is a linefeed character? should it be sent as a separate Serial.print()? An example line of code would help.
The examples are all in the link I gave you in Reply #1
The linefeed character is the code that used to be used to tell a printer to move on to the next line. The carriage-return character was used to tell the printer to return back to the start of the line. They are often used together.
You can either do
Serial.print(1024);
Serial.println();
or
Serial.println(1024);
...R
so would serial.println(1024); satisfy the else if(ch==10) and set the blinkrate to 1024?
what I am getting at is, is the ln the linefeed character, and is that character a colon?
void loop()
{
if (megaSerial.available())
{
char ch = megaSerial.read();
if (isDigit(ch))
{
value = (value * 10) + (ch - 0);
}
else if (ch == 10)
{
megaVal = value;
value = 0;
}
}
currentMillis = millis();
buttonPress = read_LCD_buttons(); // read the b
ButtonAction();
if (subMenu != subMenuPrev || menu != menuPrev || megaVal != megaValPrev)
{
updateLCD();
menuPrev = menu;
subMenuPrev = subMenu;
megaValPrev = megaVal;
}
}
void ButtonAction()
{
if (buttonPress != buttonPressPrev)
{
if (currentMillis - pressTime >= debounceTime)
{
pressTime = currentMillis;
buttonPressPrev = buttonPress;
switch (buttonPress)
{
case btnRIGHT: menu++; subMenu = 1; break;
case btnLEFT: menu--; subMenu = 1; break;
case btnUP: subMenu--; break;
case btnDOWN: subMenu++; break;
case btnSELECT: SelectAction(); break;
case btnNONE: break;
default: break;
}
if (menu > 5)
{
menu = 1;
}
if (menu < 1)
{
menu = 5;
}
}
}
}
void SelectAction()
{
}
void updateLCD()
{
switch (menu)
{
case 0: menu = 5; break;
case 1: MenuOne(); break;
case 2: MenuTwo(); break;
case 3: MenuThree(); break;
case 4: MenuFour(); break;
case 5: MenuFive(); break;
default: menu = 1;
}
}
void MenuOne()
{
if (subMenu < 1)
{
subMenu = 5;
}
if (subMenu > 5)
{
subMenu = 1;
}
switch (subMenu)
{
case 1: Show("co2"); break;
case 2: Show("dayCO2Low"); break;
case 3: Show("dayCO2High"); break;
case 4: Show("nightCO2Low"); break;
case 5: Show("nightCO2High"); break;
default: subMenu = 1;
}
}
void MenuTwo()
{
if (subMenu < 1)
{
subMenu = 7;
}
if (subMenu > 7)
{
subMenu = 1;
}
switch (subMenu)
{
case 1: Show("Temperature"); break;
case 2: Show("dayTempLow"); break;
case 3: Show("dayTempHigh"); break;
case 4: Show("mornTempLow"); break;
case 5: Show("mornTempHigh"); break;
case 6: Show("nightTempLow"); break;
case 7: Show("nightTempHigh"); break;
default: subMenu = 1;
}
}
void MenuThree()
{
if (subMenu < 1)
{
subMenu = 2;
}
if (subMenu > 2)
{
subMenu = 1;
}
switch (subMenu)
{
case 1: Show("RH"); break;
case 2: Show("rhSetpoint"); break;
default: subMenu = 1;
}
}
void MenuFour()
{
if (subMenu < 1)
{
subMenu = 5;
}
if (subMenu > 5)
{
subMenu = 1;
}
switch (subMenu)
{
case 1: Show("photoperiod"); break;
case 2: Show("hoursOn1"); break;
case 3: Show("hoursOff1"); break;
case 4: Show("hoursOn2"); break;
case 5: Show("hoursOff2"); break;
default: subMenu = 1;
}
}
void MenuFive()
{
if (subMenu < 1)
{
subMenu = 6;
}
if (subMenu > 6)
{
subMenu = 1;
}
switch (subMenu)
{
case 1: Show("dayCount"); break;
case 2: Show("uvSecs"); break;
case 3: Show("vegDays"); break;
case 4: Show("mornHours"); break;
case 5: Show("fanMins"); break;
case 6: Show("pumpSecs"); break;
default: subMenu = 1;
}
menuPrev = menu;
subMenuPrev = subMenu;
}
void Show(char *label)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(label);
lcd.setCursor(0, 1);
lcd.print(megaVal);
}
#include <SoftwareSerial.h>
SoftwareSerial unoSerial(50,51);//rx,tx
byte megaVal=0;
boolean up=true;
unsigned long currentMillis;
unsigned long uiDelay=2000;
unsigned long uiMillis;
void setup() {
unoSerial.begin(9600);
Serial.begin(9600);
}
void loop()
{
currentMillis=millis();
if(up)
{
megaVal++;
if(megaVal>=100)
{
up=false;
}
}
if(!up)
{
megaVal--;
if(megaVal<=1)
{
up=true;
}
}
if (currentMillis-uiMillis>=uiDelay)
{
uiMillis=currentMillis;
unoSerial.println(megaVal);
Serial.print(megaVal);
}
}
I updated the code and it still seems to be blocking. do I need to mess with the timeout?
println() adds a carriage return ('\r') and a line feed ('\n') to the data that is printed; it does not add a colon (':').