ATtiny85 433Mhz transmitter with I²C


Level:
Expert
Author:
published:
Modified:

This page is primarily for the dutch users, but can also apply for others because the protocols used is quite common and reused a lot. We have created a little script which does 433Mhz transmitting for some simple wall socket switches on a quite capable and nice little device, the ATtiny85


So what we did was we used the Arduino environment to program it using two popular libraries. The ATtiny85 slave i2c slave library found on the Arduino playground, and the popular remoteswitch library from 433MhzForArduino found on bitbucket and made by user fuzzylogic.

Supported switches are:

  • Elro’s
  • Switched bought from the Blokker
  • Switches bought from the Action
  • A very old flamingo AB400s switch.
  • Klik aan/Klik uit (non self learning switches).

Components

Prepare the ATtiny85

The preparation is quite simple. Just follow the instructions on how to program the ATtiny85 mentioned on High-Low tech (if you have some problems with finding the ATtiny85 in the boards list, please take a look at the github issues page at: https://github.com/damellis/attiny/issues (for arduino IDE 1.5.x users:https://github.com/damellis/attiny/issues/39) which is the High-Low tech support page for the ATtiny85 library). Be sure to select the ATtiny85 8Mhz board in the Arduino IDE and burn the bootloader. It is not really burning a bootloader, it just sets the ATtiny85 to run at 8Mhz. This is because to tiny deaults runs at 1Mhz and we can’t do I²C on that speed.

Program the ATtiny85

When you are done with preparing, meaning wiring is correct and the ATtiny runs at 8Mhz. It is time to program the tiny with our little script. It really is small. Go to the PiDome Hardware repository and browse to PT2262OrAlike433MhzTransmitter. As well as the script as the libaries are located there. If you already have installed the libraries you can discard them, just download the Arduino .ino file, and skip to program.

Download the source

To download the source for this little project go the the PiDome Hardware Downloads page. The zip file “ATtiny85_I2C_PT2262OrAlike433MhzTransmitter.zip” contains all the necessary libraries, the sketch drawing (image and fritzing) and the Arduino ino file itself.

Install the libraries

To install the libraries, copy the folder from the libraries folder in the repository to the libraries folder of your Arduino IDE installation. Start your IDE. If your IDE was already running, close and restart it.

Program

In the folder PT2262OrAlike433MhzTransmitter is another PT2262OrAlike433MhzTransmitter directory. This is where the script PT2262OrAlike433MhzTransmitter.ino lives. Open this script.
By default the I²C address is 0x25. If you want to change this go to the line containing:

#define I2C_SLAVE_ADDR 0x25 // i2c slave address

Change the 0x25 to your desired address (between 0x03 and 0x077).

Upload the code to the Arduino.

Wire it up

After you have uploaded the code to the tiny. You need to wire it up correctly. Because you want to keep it safe you want to use a logic level converter. In this setup the RF transmitter runs at 5 volts and so does the tiny. As i do not have a 433Mhz part created yet, i have put some text to show what line does what. The red little led is used to show that there is actually some signalling to the RF transmitter.

pi-attiny85-433mhz-2_bb2

Here a picture in a breadboard state:

imag0830

The green and white wire on top are actually connected to an i2c buffer in this picture. Just for testing multiple I²C devices after 16 meter of cat5 cable and a buffer.

Send commands

This part can be a little tricky. Because the current setup supports multiple devices, and device selection is done with a “prefix”. Also you need to think about characters and they’re hex and decimal values. If you take a look in the Arduino script you can see i use a character to identify the device being used. And then the rest of the input is assumed to be for that particular device.

Example

Let’s take for example the Action switch, and keep the following table next to it: http://www.asciitable.com/. You need to look at the table columns: Dec (decimal), hx (hexadecimal) and Chr (Character). We are going to use these.

The action switch is a wall socket switch with a remote. These can be configured. When you open the wall socket switch by opening the little lever on the back, you will see 10 dip switches. The switches 1 to 5 represent a “house code”. When you open the remote you will see the switches 1 to 5. So the switches 1 to 5 on the wall socket plug should have the same selection as in the remote. In this example the switch 1 in the wall plug and in the remote is set to “On”.
The dip switches 6 to 10 in the wall plug represent the “A” to “E” characters on the remote. So if the switches on the “1” and “6” are turned to the “On” position in the wall socket, it has the address “1 A”.
In this example we are controlling this action wall socket on address “1 A”.

The chip address is 0x25 on bus one, this means we have raspberry pi rev 2, if you have raspberry pi rev 1, you should use bus 0 (” -y 0 “). If you changed the address in the sketch, replace the 0x25 with that address.

This switch takes as command line to turn device “1 A” on: “i2cset -y 1 0x25 0x41 0x01 0x41 0x54 i”. And to turn it off again: “i2cset -y 1 0x25 0x41 0x01 0x41 0x00 i” (replace the last 0x54 with something else and it is seen as False (Off))

So, what are we doing here:
This switch is identified by character “A”, which is in decimal character number 65, which you can see in the sketch. So the sketch selects the action switch if the first character received is an “A” or decimal “65”, so we need to send decimal number “65” to the device. To accomplish this from the raspberry pi we use a hexadecimal notation. Character “A” = Decimal “65” = Hexadecimal “0x41”. If you take a look in the table you will see these characters and numbers on the same line.

So if you keep following the above turn device on command you are actually sending: “i2cset -y 1 0x25 A 1 A T”. Which commonly speaking is: “I want to send a command to chip on bus 1 at address 0x25 which contains: select the action device with settings at 1A and turn it on”.

The reason we are doing it this way is to make it more clear in the PiDome Server. When you add for example an action remote switch you can give the chips address where the RF transmitter is attached to. Then you select how you have configured the wall socket in this example “1A”. The “T” is just a shortcut to “True”. In this wat the configuration in the server looks a lot like the configuration you would do when configuring the wall sockets.

Supported devices command structures

Below a list of command structures per device supported, assume that all the commands are preceded with “i2cset -y 1 0x25″ and ends with ” -i”. You should also replace the [from…to] range possibilities with they’re hexadecimal equivalent.

Action device:

0x41 systemCode[1..5] device[A..E] On/Off

Blokker device:

0x42 device[1..8] On/Off

Klik aan/Klik uit (This one has two configurations, check you device to see which one you need, the first one is with group setting, the second one without) The first one has two prefix characters to make the selection of the correct device in the chip:

0x4B 0x52 address[A..P] group[1..4] device[1..4] On/Off
0x4B address[A..P] device[1..16] On/Off

The Elro devices:

0x45 systemCode[1..5] device[A..E] On/Off

The Flamingo switch (this one is specific for the AB400S)

0x46 systemCode[1..5] device[A..E] On/Off

It is possible that not all the devices respond to this. For this i’m sorry, but we are also going to work on supporting the RFXCom device. But currently it is not implemented yet. Until then. You can use this little nifty thingy.

In the servers latest snapshot the Action device XML is present. Also the above devices will be added to the server.

Until then, have fun “commandlining” on the raspberry pi with this device!

Below the setup soldered and put in a tiny 3cm (1.18 inches) case.

imag0831

Below the “tiny” in action in it’s closed case:

Latest news/blog

Friends of PiDome

UniPi.technology
Home-automation hardware manufacturer
Atlassian
Products for teams, from startup to enterprise
RFXCOM
Affordable 433Mhz RF transceivers

Latest added technology

  • SMS
  • Z-Wave
  • PushBullet
  • PlugWise
  • MQTT

Some project stats

Open Hub project report for PiDome Platform

Other

Official NLJUG Member