The basic plan is to have a Attiny85 pass information from a 433Mhz RF module to another chip/Arduino via I2C using VirtualWire and Wire libraries. I have been able to make this system work on their own using Arudino Nano's to debug, but the Attiny85 (A85) seems unable to grab the data from the RF 433 Mhz.
So have spent a few days doing some more research, and basically putting each component separate, to make sure what is being sent is correct.
- 433 Mhz transmitter is working by sending a 9 digit number, using VirtualWire.h.
- Nano with a 433 Mhz receiver is receiving 9 digit number, VirtualWire.h.
- Attiny85 is sending either a no data, or the 9 digit number, to another Nano using Wire.h.
- The Nano is getting only No Data, so the I2C is working between A85 and Nano.
Attiny85, on Pin 1 (pin 6 on chip) is not getting any data from the 433 Mhz, which works on (2). I connect the GND of the 433 RX to the chip.
Here is the Receiver code:
#include <VirtualWire.h>
#include <Wire.h>
void setup() {
pinMode(A3, OUTPUT);
Wire.begin(); // join i2c bus (address optional for master)
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(4000); // Bits per sec
vw_set_rx_pin(1);
vw_rx_start(); // Start the receiver PLL running
}
void loop() {
uint8_t buf[15];
uint8_t buflen = 15;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
digitalWrite(A3, LOW);
Wire.beginTransmission(8); // transmit to device #8
for (int i = 0; i < buflen; i++) {
Wire.write(buf[i]);
}
Wire.endTransmission(); // stop transmitting
} else {
digitalWrite(A3, HIGH);
Wire.beginTransmission(8); // transmit to device #8
Wire.write("no DATA");
Wire.endTransmission(); // stop transmitting
}
}
Here is the Transmitter code:
#include <VirtualWire.h>
int xPin = A7;
int yPin = A6;
int buttonPin = 2;
int xPosition = 0;
int yPosition = 0;
int buttonState = 0;
const char *controller;
void setup() {
Serial.begin(9600);
pinMode(12,OUTPUT);
pinMode(10, OUTPUT);
pinMode(yPin, INPUT);
pinMode(xPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
xPosition = analogRead(xPin);
yPosition = analogRead(yPin);
buttonState = digitalRead(buttonPin);
if(xPosition > 0 || yPosition > 0) {
String Data = (xPosition + yPosition);
controller = Data;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
} else {
digitalWrite(13, 0);
digitalWrite(4, 1);
controller = "#s0_0";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
}
Serial.println(controller);
}
So basically the A85 is not getting past if (vw_get_message(buf, &buflen)) { on pin 1. But does when using the Nano on pin D2, from the same transmitter, but not at the same-time of-course.
Am I using the wrong Pin on the A85? Chip pin 5 and 7 are used for the I2C so it only leaves analog pins so not sure they would work either. I also tried 8 Mhz and 1 Mhz when loading the A85.
I have tried different Cores as suggested from Google, different versions of VirtualWire and clocked the Attiny 1Mhz, 8Mhz and 16Mhz. None of have worked.
Not sure what else I am missing?