My ATTiny85 is connected to a 433 transmitter and an analog sound sensor. The 433 is working fine (using VirtualWire) but when I send the reading from the sensor all I receive is a 1.
What I would like to receive is the value between 0 and 1024 like when I print the sensor to serial. I cannot check it because the ATTiny85 had no serial out.
My code is a combination of snippets I found online, I am not happy with all the magic to format the data that needs sending. I would also like to send "Reading: 637" in stead of just the number but I find the concatenation Google results extremely complicated.
Should this code send the sensor data like 672? Could there maybe be some Fuse setting blocking the AnalogRead?
#include <VirtualWire.h>
const int transmit_pin = PB0;
const int sensor_pin = PB4;
int sensor_data;
char sensor_msg[4];
void setup()
{
vw_set_tx_pin(transmit_pin);
vw_setup(2000);
}
int count = 1;
void loop()
{
sensor_data = analogRead(sensor_pin);
itoa(sensor_data,sensor_msg,4);
vw_send((uint8_t *)sensor_msg, strlen(sensor_msg));
vw_wait_tx(); // Wait until the whole message is gone
_delay_ms(1000);
count = count + 1;
}
Receiver Code as requested
This is a Pro Mini (clone) and it has an LCD attached so I can see what is going on.
#include <VirtualWire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int receive_pin = 11;
char* testje;
void setup()
{
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
lcd.init();
lcd.backlight();
lcd.home();
lcd.clear();
lcd.print("hello");
delay(1000);
lcd.clear();
}
void loop()
{
char buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) {
int i;
// Message with a good checksum received, print it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++) {
Serial.print((char)buf[i]);
}
Serial.println();
Serial.println(buf);
lcd.clear();
lcd.print(buf);
}
}