Arduino I2C to TDA5051 to TDA5051 to another Arduino

Hi everybody,
I'd like to interface arduino with the TDA5051 component, is there someone of you that has this opportunity to test it ?

I've found X10 library but I don't know from where I've to start,

Thx for the information,
Andrea

Thanks for information :slight_smile:

So the lybrary seems similar to the wire library and I've understand well it

So, what not understand is :

  • with the component that I've seen into the link ($10 tx and $10rx), can I skip to use TDA5051 ? And then not use X10 protocol ? because is over the wireless trasmission ?

Could be great in this case because the elettrical circuit and the software coulb be simplified ... but for example if at home I've access point or audio video trasmitter that is working at 2.4 ghz could be an issues ?

In the mean time I've looked for the example

Maybe is there the way to adjust it with TDA5051 ...

the last but not the least question is which kind of Home automation modem is there inside TW523 ?

Thanks for the support :slight_smile: I've just pulled out of the drawer my old elettronics book used at school :wink:

have nice day,

Andrea

Hi KE7GKP, thanks for your explanation ;), then if i not use x10 protocol with tda5051 when my will do a elettric circuit if everything will be ok:

MASTER MODULATOR connected 220v

ARDUINO SCL (clock line) connected to TDA5051 SCL (clock line)

ARDUINO SDA (data line) connected to TDA5051 SDA (data line)

GND in common

SLAVE DEMODULATOR connected 220v

TDA5051 SCL (clock line) connected to ARDUINO SCL (clock line)

TDA5051 SDA (data line) connected to ARDUINO SDA (data line)

GND in common

could i use i2c bus arduino normally ? the wifi solution it's very efficient but more expensive

I hope to explain to you what in main clearly,

Regards,
Andrea

Ok now it's clear :slight_smile: thanks ... I'll try and then i'll let you know if you are interested :slight_smile:

But the way show to me for connected arduino to TDA5051 is correct ? I mean the pin connection ...

Thanks
Andrea

Good Morning :slight_smile: thanks again for your information ...

Now I've a looked the the VirtualWire Library and what I undestand is that :

  • the trasmitter trasmit a general message without specify how is the recipient
  • then the receiver is always listening who send a message and the with if condition if is verified do the rest ... turn on / turn off ... before i think put a control about the staus ...

Is correct ?

Thanks and enjoy the week end,
Andrea

Ok ,
now I've download RF12 and I don't know if is the correct one to use :frowning: ...

Any way the first try that i will do is that I will try is that i will do a simple send and receive and then i'll you know about the result :slight_smile: maybe it could be useful for you also :slight_smile:

Thanks Andrea

Hi :slight_smile: I'm looking the VirtualWire Library ... below is reported what it's my idea ... (is not optimized code because I've it at home ) ... is what I'm doing with i2c at moment ...

#include <Bounce.h>
#include <Wire.h>

#define buttonPin 2 // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = LOW; // variable for reading the pushbutton status

Bounce bouncer = Bounce( buttonPin,5 );

void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Wire.begin(); // join i2c bus (address optional for master)

}

void loop()
{

// Update the debouncer
bouncer.update ( );
int in = bouncer.read();

if (in == HIGH)
{
if (buttonState ==LOW)
{
buttonState = HIGH;
}
else
{
buttonState = LOW;
}
}
// turn LED on:
digitalWrite(ledPin,buttonState);
Wire.beginTransmission(4); // transmit to device #4
Wire.send(buttonState);
Wire.endTransmission();

}

SLAVE CODE :

#include <Wire.h>

const int ledPin = 12; // the number of the LED pin

void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
pinMode(ledPin, OUTPUT);
}

void loop()
{

delay(3000); //Wait 2 Second before re-excute
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
//while(1 < Wire.available()) // loop through all but the last
//{
int x = Wire.receive(); // receive byte come un integer
if (x == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(x);

}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println(x);
}
//}
}

Mainly I've to adjust this producere for virtual wire library ... could you give me some indication ?
Thx for your great support
Andrea

thanks before to put a code I've look for the code button :slight_smile: now I've learn a new things ...

so you have reason ... the code was only for tell you which is my idea and what I've did right now ...

when I'll at home i'll write a code with with virtual library and then i'll post it,

Regards,
Andrea

Hi KE7GKP,
I wrote the Master Code: when I press the button should send out the button value :

#include <VirtualWire.h>
#include <Button.h>
Button sw(2, PULLUP);
#define buttonPin 2     // the number of the pushbutton pin
int buttonState = LOW;   // variable for reading the pushbutton status
const int ledPin =  13;  // the number of the LED pin
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;  // What is the function ? is end code ?

void setup()
{
  // Initialise the IO and ISR
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_set_ptt_pin(transmit_en_pin);
  vw_set_ptt_inverted(true); // what is the function for that ?
  vw_setup(2000);	 // Bits per sec
  pinMode(buttonPin, INPUT); //Initialize the button in input
  
}

void loop()
{
  
 if(sw.uniquePress())
   {
     buttonState = !buttonState; 
      digitalWrite(ledPin,buttonState);  
      vw_send((uint8_t *)buttonstate, 1); // send out the button state ? correct ?
      vw_wait_tx(); // Wait until the whole message is gone
      digitalWrite(led_pin, LOW);
      delay(1000);
     
   } 
 
}

If it is correct can i proceed to put the receiver code :wink: thanks have nice day Andrea

If it is correct

Did you at least try to verify it?

      digitalWrite(led_pin, LOW);

I don't see led_pin defined anywhere.

  pinMode(buttonPin, INPUT); //Initialize the button in input

You've already handed over control of this pin to the Button class.

Hi the first one comment have you reason,
What I would like to do here send out via serial the status button ...

The line below reported is correct from the compilator

vw_send((uint8_t *)buttonState, 1);

but I don't know if is correct logical stand point because I don't know what is doing uint8_t ...

So, now is compiling correctly ...

Regards,

Andrea

The vw_send function only knows how to send byte arrays. So, the (uint8_t *) part is a cast. It is treating your int variable, buttonState, as though it was a pointer to an array of bytes. You are sending the first byte in that array, which will be the high byte, which will always be 0.

Either change the type of buttonState to byte or change the number of bytes sent to match the number of bytes in an int (2). If you do the latter, be sure to take that into account when writing the receiver code.

Ok I understand what you mean correct me if wrong please ...
something like that :

char buttonState = LOW;

In this case the system will write 0 like a char correct ?

Thanks
Andrea

char and byte are the same size, and store the same kind of data. 0 and '0' are not the same value, though. Storing 0 in a char will not make it a '0'.

Ok this is true ... but if i put into char buttonState = (LOW,DEC); the result will be 0 ... so I've tried and seems
that ... then with the receiver should not be a issues ... I'd like to understand how to use uint8_t * correctly in my code ...

Thanks
Andrea

but if i put into char buttonState = (LOW,DEC); the result will be 0

So don't do that. First, the comma operator may not be doing what you think it is doing. so the value stored in buttonState may not be what you think it is. If you want to store '0' or '1' in buttonState, based on LOW or HIGH, use

buttonState = HIGH + '0';
buttonState = LOW + '0';

Or explain what it is you are trying to store in buttonState.

Good Morning,
then code for the Master should like this:

#include <VirtualWire.h>
#include <Button.h>
Button sw(2, PULLUP);
#define buttonPin 2     // the number of the pushbutton pin
char buttonState = LOW + '0';   // variable for reading the pushbutton status
const int ledPin =  13;  // the number of the LED pin
const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;  // What is the function ? is end code ?
void setup()
{
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_set_ptt_pin(transmit_en_pin);
  vw_set_ptt_inverted(true); // what is the function for that ?
  vw_setup(2000);	 // Bits per sec
  pinMode(buttonPin, INPUT); //Initialize the button in input 
}

void loop()
{
 if(sw.uniquePress())
   {
     buttonState = !buttonState + '0'; // here I need to revert the value if is 0 when press the button should became 1 and viceversa 
      digitalWrite(ledPin,buttonState);  
      vw_send((uint8_t *)buttonState, 1); // send out the button state ? correct ?
      vw_wait_tx(); // Wait until the whole message is gone
      delay(1000);     
   } 
}

I don't know if is right ...
what i'd like to do is :

  • press the button then send on --> 1
  • press the button again send off --> 0
  • for do that I do a "not" of my variabile but the problem if that is char and not integer ... then not of 0 is 1 but not of 1 is not 0 ...

also i don't understand that

vw_send((uint8_t *)buttonState, 1);

so vW_Send is the function for send
uint8_t * --> what does it mean ?
1 --> What does it mean ?

could explain kidly to me shortly ?

Thanks
Andrea

First, it is important to make it clear when you are talking about the number 0 and the letter '0' (or the number 1 and the letter '1').

Second, you perhaps need to explain why you think you need to send the letter '0' or the letter '1' when the button is pressed.

Why not just make buttonState a byte variable, and send the number 0 or the number 1? As long as the receiver knows whether it is supposed to get a number or a letter, what difference does it make?

also i don't understand that

vw_send((uint8_t *)buttonState, 1);

so vW_Send is the function for send
uint8_t * --> what does it mean ?
1 --> What does it mean ?

First, the function call should be:

vw_send((uint8_t *)&buttonState, 1);

Yes, vw_send is a function that you are calling. It takes two arguments. The first is a pointer to some bytes to send. The second is the number of bytes to send.

The &buttonState says to take the address of the variable (i.e. treat it like a pointer).

The (uint8_t *) part says that we want to cast the pointer (to int) to a pointer to byte (that's what a uint8_t is). That is, we want to treat the pointer to int as though it was a pointer to byte. Since the pointer points to the first byte of the int, we can do this.

Since the amount of data we want to send is 1 byte, that's the value that we supply for the second argument.

then i not understood bad correct me if i wrong please ... I can declare
byte buttonState = LOW;
In this way the lenght of that I will send will be long one 1 byte ...

then when I call the function

vw_send((uint8_t *)&buttonState, 1);
uint8_t * is the cast but the cast is necessary ?

sorry it's more clear than before ...