Help with Simple ESP32 sketch and MEGA-io board

Bionic-Bean

New member
Hi Guys, Just started getting back into using my MEGA-io 8 relay board and trying to connect to ESP32.
I can connect OK and talk to the MEGA baord nad the ESP returned an I2c scan of (0x31).
What Im trying to do is a very simple sketch for the ESP32 to turn on any of the relays.
Preferably using the Wire.begin() .
example....
Wire.begin();
}
void loop() override {
Wire.beginTransmission(0x31); // Mega sitiing at address 0x31
Wire.write(0x00);
Wire.write(2);
Wire.endTransmission();

Not sure of the correct way to address the board in order to turn any relay on. Hence a simple sketch to get me going and then I can modify .
Thanks in advance
Dave
 

alexburcea

Moderator
Staff member
Hi,
All our cards act as a memory on I2C so you have to provide the I2C hardware address and the memory address to read or write something from the card.
Your code is correct, the first Wire.write() represent memory address and the second represent the value.
If you wish to control the relays, you have 2 posibilities:
1) Write all relays state a a bitmap at the address 0x00
2) Write the number of the relay (1 based) at the address 0x01 to turn on a single relay (left the rest untouched) and write the number of the relay at address 0x02 to turn off one relay (left the rest untouched).
All addresses of the card parameters can be found on GitHub : https://github.com/SequentMicrosystems/megaio-rpi/blob/master/megaio.h
You can also look at the arduino library made for the current "megaio" card : https://github.com/SequentMicrosyst...-Library/blob/main/src/SM_Home_Automation.cpp
 

Bionic-Bean

New member
Hi Alex, thanks for reply and clarification on the code looking OK. Found out i had a couple of extra lines before the wire.begin that simply stopped the wire.begin from hapening. No errors anywhere, just would not exercute wire.begin.
Making slow progross and trying to remember code after a few years away doing other stuff. Now have the relay chattering away and inputs displaying. :)
Thanks Again. very much appreciated.
 
Top