Good evening to every one.
I have connected an attiny85 to an Arduino board via Software Serial library(ATtiny85 chip pins are 2=rx and 3=Tx and on the Arduino board are the numbers 4=Rx and 6=Tx).
When the '85 sends a data, -1 appear among the chars arriving from the attiny85, why happen?
If, an example, the attiny sends this V88.66
Arduino receive these V -1 -1 -1 8 8 . 6 -1 6
or, in bytes, 86 255 255 255 56 56 46 54 255 54
I have tried other libraries but nothing has changed.
Can anyone could be help me? Thanks :-)
Antonio (Italy)
Arduino board: Arduino UNO 16 MHz
Attiny85: Vcc5V, fclock = internal, 8MHz
IDE version: 1.8.12
The code of the Attiny85:
#include <SoftwareSerial.h>
#define Rx 3 // 3=pin2
#define Tx 4 // 4=pin3
SoftwareSerial NSP(Rx, Tx);
float i, num;
void setup()
{
NSP.begin(38400);
}
void loop()
{
num = i/3;
NSP.print("V");
NSP.println(num);
delay(10);
i++;
}
The code of Arduino board:
#include <SoftwareSerial.h>
SoftwareSerial ss(4, 6); // 4=Rx, 6=Tx
char c;
String comando;
void setup()
{
pinMode(4, INPUT_PULLUP);
pinMode(6, OUTPUT);
ss.begin(38400);
Serial.begin(2000000);
}
void loop()
{
if(ss.available()) //lettura dati da porta seriale
{
// c = ss.read();
// Serial.println(c);
do
{
c = (ss.read()); //acquisisci fintantoche...
if (c != '\n') // && c > -1) //non appare il carattere di fine riga
{
comando = comando + c; //nel frattempo aggiungi il carattere letto alla stringa
}
} while(c != '\n'); //rimani nel ciclo fino a che non arriva il fine riga
Serial.println(comando);
c = ' ';
comando = "";
}
}