so have split program 2 micros per request on complicate project client. wants system wireless eventually, i'm setting serial until parts , stuff arrive finish this. have tiny84 doing heavy work , sending telemetry arduino. arduino needs able send couple numbers tiny84 ndicate program setting. 1 step @ time.
tiny84 code:
arduino code:
at moment, nothing showing on lcd screen (with exception of loading message, lcd works). opened serial monitor on arduino , every , again i'm getting value tiny84. they're right values. smashed back, no new line, , don't appear every time values change they're supposed to. heck if know. project used simple.
tiny84 code:
code: [select]
#include <softwareserial.h>
// set tx , rx pins softwareserial
int txpin = 0;
int rxpin = 1;
// declare object
softwareserial serial(txpin, rxpin);
// declare , set pin names
int fanpwm = 2; // digital pin 2: 120a pwm controlled dc fan\motor controlled ti csd18503kcs 40v n-channel nexfet™ power mosfet
int temperatureadc = 7; // analog pin 7: analog voltage controlled temperature probe
// declare variables
double temperatureval; // variable store value analog temperature probe
double prevtemperatureval; // variable store previous value analog temperature probe
void setup() {
//set io pins
pinmode(fanpwm, output); // set output pin pwm controlled dc fan
serial.begin(9600); // start serial output
}
void loop() {
temperatureval = analogread(temperatureadc); // reads temperature probe (value between 0 , 1023)
analogwrite(fanpwm, temperatureval / 4); // scale range (0 255) , write scaled value pwmfan pin
//write fan speed , temperature value softserial
if (temperatureval != prevtemperatureval) {
serial.print(temperatureval); // print ascii-encoded decimal
prevtemperatureval = temperatureval;
}
delay(200);
}
arduino code:
code: [select]
#include <liquidcrystal.h>
// declare io pins
int lcdbacklight = 3; //digital pin 3: lcd backlight
//declare variables
double temperatureval;
double prevtemperatureval;
// set lcd pins
liquidcrystal lcd(2, 8, 4, 5, 6, 7);
void setup() {
// set lcd's number of columns , rows:
lcd.begin(16, 2);
// initiate , turn on backlight
pinmode(lcdbacklight, output);
digitalwrite(lcdbacklight, high);
lcd.setcursor(0, 0);
lcd.print("loading...");
// initialize serial communications:
serial.begin(9600);
delay(1000);
lcd.clear();
}
void loop() {
// when characters arrive on serial port...
if (serial.available()) {
// wait bit entire message arrive
delay(100);
// read available characters
while (serial.available() > 0) {
temperatureval = serial.read();
// display each character lcd
lcd.setcursor(0, 0);
lcd.print((int)((temperatureval*100l) / 1023)); // scale range (0 100)
lcd.print("% ");
}
}
}
at moment, nothing showing on lcd screen (with exception of loading message, lcd works). opened serial monitor on arduino , every , again i'm getting value tiny84. they're right values. smashed back, no new line, , don't appear every time values change they're supposed to. heck if know. project used simple.
of course there's no newline, why there be? if want newline between them, use serial.println() not serial.print(). code doesn't need that
you should test arduino side serial monitor - find won't work. serial.read() gets single character @ time (among other things)
serial.parseint() might want. https://www.arduino.cc/en/reference/parseint
you should test arduino side serial monitor - find won't work. serial.read() gets single character @ time (among other things)
serial.parseint() might want. https://www.arduino.cc/en/reference/parseint
Arduino Forum > Using Arduino > Programming Questions > Serial Communication Between Tiny84 and Arduino
arduino
Comments
Post a Comment