Software serial between Arduino and ATtiny85/ATtiny84.......... SOLVED!!!

Hello everybody, I have serial communication between arduino and attiny84 and it works well except something which is bothering me.

An attiny84 sending measured voltage value to arduino nano every single second.

Here's the code for arduino

#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial mySerial (rxPin, txPin);

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

And here's the results

V= 2548.69
V= 2549.63
V= 2549.25
V= 2550.00
V= 2549.81
V= 2550.56
V= 2549.06
V= 2549.63
V= 2550.38
V= 2550.19
V= 2550.00
V= 2550.38
V= 2550.56
V= 2550.56
V= 2550.94
V= 2550.94
V= 2551.69
V= 2551.13
V= 2550.75

But, because I want to send many values more than the measured voltage (V), so I need to separate the value. I wrote this simple code as a begin.

#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial mySerial (rxPin, txPin);
String incomming = "" ;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop() {
  if (mySerial.available ()) {
    incomming = mySerial.read();
    incomming.trim();
    Serial.println(incomming);
  }
}

And the results

86
61
32
50
53
54
48
46
49
51
13
10
86
61
32
50
53
53
57
46
51
56
13
10
86

Anyone can tell me how to get rid of ascii or why the results are in asccii?

BTW, if i change the read line to readString, i'll get nothing just an empty serial :slight_smile: :slight_smile: :slight_smile:

Regards,
Tommy

Can you provide the code that's running on the attiny? In my understanding the Serial.read() function returns only one byte at a time. Your required information might simply be cut off and sent as the net output.

Of course exactly this

Jocobes:
In my understanding the Serial.read() function returns only one byte at a time. Your required information might simply be cut off and sent as the net output.

exactly this, so the one byte is stored in your String and then printed (instead of written as before) there are good ways in Serial Input Basics to transfer data between 2 units.

Jocobes:
Can you provide the code that's running on the attiny?

Here's my code on attiny84

#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
#include <SoftwareSerial.h>
#define rxPin   9
#define txPin   10
SoftwareSerial mySerial(rxPin, txPin);
String Value = "" ;
void setup(void) {
  mySerial.begin(9600);
  ads.begin();
}

void loop(void) {
  int16_t results;
  results = ads.readADC_Differential_0_1();
  float multiplier = 0.1875F;
  float Voltage = results * multiplier;
  Value = Voltage ;
  mySerial.println("V= " + Value);
  delay(1000);
}

I don't think the problem with this code. It works on first code which I posted

SOLVED!!!

You won't believe this guys, but, after adding those two lines so it works :slight_smile: :slight_smile: :slight_smile:

Serial.setTimeout(100);
  mySerial.setTimeout(100);

I don't know whats the relationship between Timeout and filling the string lol

Thank you all guys for help and hope this topic can help someone else with the same issue!

Regrds,
Tommy