Archive for the ‘Arduino’ Category


Improve your retro gaming emulation experience by using the systems original controller

This post provides instructions so you can bring back to life your old controller with native plug-and-play support for Microsoft Windows 7+ and Linux/RetroPie using an ATmega32u4 based Arduino.

File 12-07-2016, 18 38 47
File 12-07-2016, 18 39 06

Ever since Arduino’s started to appear with the ATmega32u4 chip which allows the creation of USB devices I’ve wanted to create adapters to reuse my old game controllers on modern hardware. Unfortunately the official libraries didn’t support joystick/gamepads only keyboard and mouse. Thankfully Matthew Heironimus started a project to address this exact situation with his Arduino Joystick Library http://mheironimus.blogspot.co.uk/2015/11/arduino-joystick-library.html.

Using Matthew’s library and the following sketch https://github.com/jfrmilner/Arduino-USBRetroGamingControllers/blob/master/SegaMasterSystem_GamePad_USB/SegaMasterSystem_GamePad_USB.ino you can easily create an adapter for your controller following these steps

1. Get a suitable connector. For this project you’ll need to search (eBay/Aliexpress) for a SNES Controller Extension. Cut into the cable and expose the wires, this is the one I used
Controller_SNES_Extension
2. Find the pinout for your controller. PINOUTS.RU is a good source, for example here is the one for the SNES Controller http://pinoutsguide.com/Game/snescontroller_pinout.shtml. Use a multimeters continuity test to quickly map the pins to wires.
3. Wire the connector to the Arduino. I’ve included the pin information in the Arduino sketch, so for example SNES proprietary connector Pin1 goes to Arduino +5v.
4. Install Matthew’s library from https://github.com/MHeironimus/ArduinoJoystickLibrary. See https://www.arduino.cc/en/Guide/Libraries for more information.
5. Upload the Arduino Sketch and then connect your controller.
6. Test. Windows’s users should be able to see the controller appear as a gamepad which will be named after your Arduino board, for example.
Controller_DeviceAndPrinters
Windows provides a helpful test program on the properties page of the controller
Controller_DeviceAndPrinters_Properties
7. Play. For SNES Emulation I recommend Snes9x http://www.snes9x.com/.

Thanks for reading and be sure to check out my other controller conversions.

Kind Regards, jfrmilner


Improve your retro gaming emulation experience by using the systems original controller.

This post provides instructions so you can bring back to life your old controller with native plug-and-play support for Microsoft Windows 7+ and Linux/RetroPie using an ATmega32u4 based Arduino.
File 10-07-2016, 13 49 04
File 10-07-2016, 13 49 23
Ever since Arduino’s started to appear with the ATmega32u4 chip which allows the creation of USB devices I’ve wanted to create adapters to reuse my old game controllers on modern hardware. Unfortunately the official libraries didn’t support joystick/gamepads only keyboard and mouse. Thankfully Matthew Heironimus started a project to address this exact situation with his Arduino Joystick Library http://mheironimus.blogspot.co.uk/2015/11/arduino-joystick-library.html.

Using Matthew’s library and the following sketch https://github.com/jfrmilner/Arduino-USBRetroGamingControllers/blob/master/SegaMegaDrive_GamePad_USB/SegaMegaDrive_GamePad_USB.ino you can easily create an adapter for your controller following these steps

1. Get a suitable connector. For this project you’ll need to search (eBay/Aliexpress) for a DE9 or DB9 Male Breakout board, this is the one I used
DB9
2. Find the pinout for your controller. PINOUTS.RU is a good source, for example here is the one for the MegaDrive Controller http://pinouts.ru/Game/genesiscontroller_pinout.shtml
3. Wire the connector to the Arduino. I’ve included the pin information in the Arduino sketch, so for example DE9 Pin1 goes to Arduino Pin 1 (Up).
4. Install Matthew’s library from https://github.com/MHeironimus/ArduinoJoystickLibrary. See https://www.arduino.cc/en/Guide/Libraries for more information.
5. Upload the Arduino Sketch and then connect your controller.
6. Test. Windows’s users should be able to see the controller appear as a gamepad which will be named after your Arduino board, for example.
Controller_DeviceAndPrinters
Windows provides a helpful test program on the properties page of the controller
Controller_DeviceAndPrinters_Properties
7. Play. For MegaDrive emulation I recommend the Fusion Emulator for Sega Systems (google fusion364)

Thanks for reading and be sure to check out my other controller conversions.

Kind Regards, jfrmilner


Improve your retro gaming emulation experience by using the systems original controller

This post provides instructions so you can bring back to life your old controller with native plug-and-play support for Microsoft Windows 7+ and Linux/RetroPie using an ATmega32u4 based Arduino.
File 13-07-2016, 20 55 21
File 13-07-2016, 20 56 07
Ever since Arduino’s started to appear with the ATmega32u4 chip which allows the creation of USB devices I’ve wanted to create adapters to reuse my old game controllers on modern hardware. Unfortunately the official libraries didn’t support joystick/gamepads only keyboard and mouse. Thankfully Matthew Heironimus started a project to address this exact situation with his Arduino Joystick Library http://mheironimus.blogspot.co.uk/2015/11/arduino-joystick-library.html.

Using Matthew’s library and the following sketch https://github.com/jfrmilner/Arduino-USBRetroGamingControllers/blob/master/SegaMasterSystem_GamePad_USB/SegaMasterSystem_GamePad_USB.ino you can easily create an adapter for your controller following these steps

1. Get a suitable connector. For this project you’ll need to search (eBay/Aliexpress) for a DE9 or DB9 Male Breakout board, this is the one I used
DB9
2. Find the pinout for your controller. PINOUTS.RU is a good source, for example here is the one for SMS Control Pad http://pinouts.ru/Game/sega_ms_joy_pinout.shtml
3. Wire the connector to the Arduino. I’ve included the pin information in the Arduino sketch, so for example DE9 Pin1 goes to Arduino Pin 2 (CONTROL_PAD_UP).
4. Install Matthew’s library from https://github.com/MHeironimus/ArduinoJoystickLibrary. See https://www.arduino.cc/en/Guide/Libraries for more information.
5. Upload the Arduino Sketch and then connect your controller.
6. Test. Windows’s users should be able to see the controller appear as a gamepad which will be named after your Arduino board, for example.
Controller_DeviceAndPrinters
Windows provides a helpful test program on the properties page of the controller
Controller_DeviceAndPrinters_Properties
7. Play. For SMS emulation I recommend the Fusion Emulator for Sega Systems (google fusion364)

Thanks for reading and be sure to check out my other controller conversions.

Kind Regards, jfrmilner


Improve your retro gaming emulation experience by using the systems original controller
This post provides instructions so you can bring back to life your old controller with native plug-and-play support for Microsoft Windows 7+ and Linux/RetroPie using an ATmega32u4 based Arduino.

Controller_C64-02
Controller_C64-01

Ever since Arduino’s started to appear with the ATmega32u4 chip which allows the creation of USB devices I’ve wanted to create adapters to reuse my old game controllers on modern hardware. Unfortunately the official libraries didn’t support joystick/gamepads only keyboard and mouse. Thankfully Matthew Heironimus started a project to address this exact situation with his Arduino Joystick Library http://mheironimus.blogspot.co.uk/2015/11/arduino-joystick-library.html.

Using Matthew’s library and the following sketch https://github.com/jfrmilner/Arduino-USBRetroGamingControllers/blob/master/ClassicJoyStick_USB/ClassicJoyStick_USB.ino you can easily create an adapter for your controller following these steps

1. Get a suitable connector. For this project you’ll need to search (eBay/Aliexpress) for a DE9 or DB9 Male Breakout board, this is the one I used
DB9
2. Find the pinout for your controller. PINOUTS.RU is a good source, for example here is the one for C64 Control Port http://old.pinouts.ru/Inputs/ControlPortC64_pinout.shtml
3. Wire the connector to the Arduino. I’ve included the pin information in the Arduino sketch, so for example DE9 Pin1 goes to Arduino Pin 2 (JOY_UP).
4. Install Matthew’s library from https://github.com/MHeironimus/ArduinoJoystickLibrary. See https://www.arduino.cc/en/Guide/Libraries for more information.
5. Upload the Arduino Sketch and then connect your controller.
6. Test. Windows’s users should be able to see the controller appear as a gamepad which will be named after your Arduino board, for example.
Controller_DeviceAndPrinters
Windows provides a helpful test program on the properties page of the controller
Controller_DeviceAndPrinters_Properties

7. Play. For C64 emulation I’ve had great success with VICE http://vice-emu.sourceforge.net/ on both Windows and Linux (RetroPie)

Thanks for reading and be sure to check out my other controller conversions – https://github.com/jfrmilner/Arduino-USBRetroGamingControllers

Kind Regards, jfrmilner


In this project I detail how I created an Internet light controlled Christmas tree. Last year I heard about a great project by ioBridge Labs named CheerLights but unfortunately at the time this was late December and it was simply too late for me to join in, well not this year! The idea of CheerLights is a simple one: connect a strip of RGB LEDs to an Internet connected Microcontroller and have it query the CheerLight servers for the current colour, now the real magic here is that anyone can synchronously change the colour of every CheerLights setup by sending a Tweet with Hashtag #CheerLights, for example

Here’s a quick video from ioBridge about CheerLights including a demo

If you’d like a go yourself please choose from the following supported Colours:

Red
Green
Blue
Cyan
White
Warmwhite / Oldlace
Purple
Magenta
Yellow
Orange
Pink

You can see what the latest colour is right now by visiting www.cheerlights.com or https://thingspeak.com/channels/1417, getting the app android/iPhone and there is even a Google Chrome plugin but at the time of writing this is missing some of the new colours.

The Build

As with all projects of this nature, they can be customised to your own personnel preferences so I’ll not tell you what you should get but instead what I used for this build and I’ll try and highlight some pointers. I’ve got a few Arduino MCUs now, in fact I’m beginning to wonder if I’ve inadvertently become a collector as it seems I’ve just about one of each type, so from my stock I decided on a combination of Arduino Uno and Arduino WiFi Shield. The only real requirement here is that you use an MCU that you are comfortable with, if you have the same hardware (or similar – replacing the WiFi Shield with the Ethernet Shield would require minimal code changes) then you can simply upload my Sketch and away you go.
To control the LEDs I decided to use the FastLED Animation Library. This is quite a mature project and the library makes for some simple and easily readable code. FastLED supports popular LEDs including Neopixel, WS2801, WS2811, WS2812B, LPD8806, TM1809, and more so plenty of options. I went with a string of 25 WS2801 from raspimart.co.uk.

WS2801

 

You’ll also need a Christmas Tree, I picked up a desktop sized one from eBay – http://www.ebay.co.uk/itm/381033205884

ChristmasTree

 

Power

Be sure to get a power supply that can output at the correct voltage and has sufficient ampere to run the lights. Looking at the spec of my lights I know I needed a 5volts 2A (60mA*25=1500mA) AC Adaptor. I used a single AC Adaptor to power both the Arduinos and the LEDs with a splitter.

Tip: Don’t use the VIN on the Arduino to power more than 1A as this is the maximum tolerance of the forwarding diode, instead use a splitter.

The Code

Sketch flow
Boot up and connect to WiFi (halt on no connection) and run the Startup Routine (clears LEDs Black-White-Black)
Set current colours to black.
Start loop – { Check for current colour via ThingSpeak API
If it’s the same as the last check then wait and check again, if we’ve checked a couple of times without change then play either the Sparkle* or Twinkle* effect.
If the colour is different; then transition from the original colour to the new colour via the RGB colour wheel (see below image) using the shortest path, for example Red>Green would transition via Orange and Yellow or Blue>Red would transition via Magenta-Pink.
}

RGBColourWheel

 

*The Sparkle effect increases the brightness of a single LED and runs that back and forth over the strip.
*The Twinkle effect creates a FastLED Colour pallet of the current colour with black stripes which is then looped over the LED strip.

FastLED
I’m using the FastLED library which made coding these transitions and effects extremely simple.. The FastLED library has a lot to offer, one of my favourites is its ability to allow for compact colour palettes which use very little of my precious Arduino RAM, here’s a sample of the help section which explains this feature:

Normally, in computer graphics, the palette (or “color lookup table”) has 256 entries, each containing a specific 24-bit RGB color. You can then index into the color palette using a simple 8-bit (one byte) value. A 256-entry color palette takes up 768 bytes of RAM, which on Arduino is quite possibly “too many” bytes. FastLED does offer traditional 256-element palettes, for setups that can afford the 768-byte cost in RAM. However, FastLED also offers a compact alternative. FastLED offers palettes that store 16 distinct entries, but can be accessed AS IF they actually have 256 entries; this is accomplished by interpolating between the 16 explicit entries to create fifteen intermediate palette entries between each pair.

If you’re interested in lighting effects then I suggest you take a look at the Wiki

You can pick up a copy my code from GitHub – https://github.com/jfrmilner/Arduino-CheerLights

Here’s a quick demo of it in action

Thanks for reading and good luck with setting up your tree

Merry Christmas!

jfrmilner


This post will detail how I created a simple home automation project to control multiple power outlets using an Arduino Mega microcontroller.

Project highlights:
•    Reduce the amount of systems left on standby and ultimately reduce the amount of wasted energy.
•    Remotely control the power state of multiple devices.
•    Power on and off a media server by using the Power button on the front of the computer.
•    Control a collection of radio frequency (RF) devices, including single sockets and power strips.
•    Control a couple of Power Distribution Unit’s (PDU).
•    Collect and present power state information via a web page that is iDevice mobile friendly.
•    Control all the above using a single Arduino Mega with an Arduino Wiznet Ethernet Shield.

The ability to remotely manage the power states of a computer or external device over the internet can be very expensive using traditional off the shelf products, in this post I’m going to show you how I achieved this using a single Arduino. I use wireless RF and IP controlled devices for all mains power related switching so there is no risk of high voltage shocks.
This project could be recreated exactly by others but I believe that it’s more likely that people will pick and choose areas of this project and implement these into their own. The code has been made available and is fairly simple to follow due to the use of functions and comments.

As this is a physical computing project I decided to do a quick overview video to accompany this post.

This video is best viewed in 1080p HD.

Bill of materials:

# Name Price Shop
1 Arduino Mega £20 Google/eBay
2 433 Mhz Transmitter and Receiver £3 eBay: search for “Arduino 433″ or “RF Link kit”
3 Energenie Trailing Gang with Four Radio Controlled Surge Protected Sockets £20 https://energenie4u.co.uk www.amazon.co.uk
4 Opengear IP PDU ? http://www.digipower.com.tw/PDU/BravoPDUswitched.htm
5 Breadboard and a few jumper cables Google/eBay
6 2N2222 NPN bipolar junction transistor £1 http://en.wikipedia.org/wiki/2N2222

Step One – Directly connected PC
I thought it would be interesting to use a remote method to power up and shutdown a PC by directly connecting to the power button. I opened the case and popped the power switch out, on inspection it was clear that this is just a little push switch. I cut into the cable and added an electrical block connector and gave a quick test to confirm I could power it on and off by simply connecting these two wires. As I wanted to have an Arduino create the connection I decided to use a 2N2222 transistor as I had a couple of these already, you could just as easily use a relay. The connections were as follows:

Pin (flat side to front) Name  Arduino
E – Left Emitter Ground
B – Middle Base Signal (from Arduino)
C – Right Collector Power

I used a 10k resistor between the Arduino and the base of the transistor to add a little protection to the Arduino. You can see from the code that I connected the base pin to pin 8 on the Arduino. Pin 8 need to be set to OUTPUT (pinMode(8, OUTPUT);) and then I to simulate a button press I used the following code:

digitalWrite(8,HIGH);
delay(500);               // wait for half a second
digitalWrite(8,LOW);

To check that the operating system is up I wanted to send ping packets and report on the response, I found a ping library at http://www.blake-foster.com/projects/ICMPPing.zip. Blake created a similar project to this step and I encourage you to check out his site.

Step Two – Energenie RF Power Sockets
This step has been covered in separate blog posts so as not to repeat myself I will provide the links below.
Capture the RF codes for your Energenie Power Strip
https://jfrmilner.wordpress.com/2012/12/30/powershell-power-sockets-arduinorf-part-1-capture-the-rf-codes-for-your-energenie-power-strip/
Configure the circuit like I did in the following post, the code/sketch is similar with the most obvious change being the use of serial as input over web which I’m using in this project.
https://jfrmilner.wordpress.com/2012/12/30/powershell-power-sockets-arduinorf-part-2-configure-the-arduino-with-the-rf-transmission-sketch-for-your-energenie-power-strip/

Step Three – IP PDU’s
Again, this step has been covered in a previous post – https://jfrmilner.wordpress.com/2013/01/06/controlling-an-ip-pdu-with-powershell/. As I needed to have the Arduino do the authentication to the IP PDUs I needed to form an HTTP GET request with the username and password encoded. I used the website http://www.motobit.com/util/base64-decoder-encoder.asp which allowed me to encode the default credentials, for example
Username:snmp
Password:1234
Concatenated with a colon join: snmp:1234
Base64 encoded string: c25tcDoxMjM0

To complete the example, below is a code sample of one of the functions I use to collect state information from the PDUs. This clearly shows the use of the authentication code:

client.print("GET /");
client.print(powerState);
client.print("s.cgi?led=");
client.print(LEDCode);
client.println("0000000000000000");
client.print("Host: ");
client.println(hostname);
client.println("Authorization: Basic c25tcDoxMjM0");
client.println("User-Agent: Arduino Sketch/1.0 snmp@1234");

Step Four – The Web Portal/Server
Writing a web server for an Arduino is challenging mainly due to the amount of RAM available. Originally I started this project with an Arduino Uno which is limited to 2K, I maxed this out almost immediately* so I decided to get an Arduino Mega with 8k of RAM. Using the Simple Web Server sketch provided in the Arduino IDE as the starting point I created an HTML table to display the power buttons of the Energenie power strip, this code used up a lot of the available RAM. When I started to add further table rows I soon realised that I would not be able to fit the desired 21 I needed using this format. The solution I used is to have the unique information about these devices within an array and then loop through them to build the page for each client request. This made the code a little more complex but allowed massive reductions in the amount of code I needed to store within RAM.

* see the freeRam code block at – http://playground.arduino.cc/Code/AvailableMemory for an easy way to see memory utilization

Using the original web portal interface for the IP PDUs it required multiple actions to change a power state which I didn’t want and as I have two PDUs I needed to log into each one individually. This should not be considered as a design issue with the devices it’s just that they were not designed for such frequent use or outside a server cabinet for that matter!

IPPDU-05

Instead I wanted it to be mobile friendly so I needed large buttons that were colour coded to their respective devices power state, the below screenshot is taken from my iPad

WebPortal-iPad-1

You will notice that the page fits perfectly; this was achieved by adding this line to the HTML page

<meta name="viewport" content="width=device-width" />

It basically resizes the table to fit to the mobile devices landscape screen resolution and works well on all my iDevices.

In effort to keep the code line count and size down you will notice I created three functions within the Arduino sketch
1.    PDUWebStatus  – Enumerate power states on PDUs
This code queries the current power state of the PDUs and stores the results in an array for use by the aforementioned HTML table loops.
2.    PDUWebCommand – Issue power state changes on the PDUs
This code actions PDU power state change requests.
3.    PDUWebCommandPush – Collect current power state and rotate
This code uses the above two functions to action the HTML button pushes.

Whenever a user presses one of the HTML buttons they call a small javascript function that then calls the PDUWebCommandPush function mentioned above. This makes the users browser send a GET request to the Arduino which then gets matched to one of the predefined actions, for example Energenie Socket 1 On button would trigger the following action

if(buffer.indexOf("GET /?E1=ON")&gt;=0) {
mySwitch.send(4314015, 24);
refreshRequired = 1;
}

You will also notice that this sets the refreshRequired variable, this is used to force the client back to the webservers root directory and allow the changes of power states to be show on the page. I found that redirecting the users back to the root also prevented the refresh button on a browser sending an additional GET request to an already completed request.

Sets
At the time of writing this blog post I only have a single Set as listed on the above image as “Set – 1” but I have plans to add several more. Sets allow me change the power state on multiple devices at once even if they differ power source and/or control method. I have used this to power on my desktop computer and all associated monitors, this is shown in the demo video which accompanies this post.

A note on security
I have controlled access to the Arduino web server using the firewall on my router. This has allowed me to restrict access to my place of work and my internal LAN only.

The Code
The Arduino Sketch can be found over on my GitHub

Well I hope you’ve enjoyed reading about this project as much as I enjoyed putting it together. Please use any of the ideas and code in your own projects but please do give credit to the original author.

Kind Regards

jfrmilner


First Post 1 of 3

Previous Post 2 of 3

So to summarize we have collected all the RF codes for my Energenie Power Strip, created a Sketch on an Arduino connected to a an RF transmitter the only thing left it to use PowerShell to send Serial commands.

Now for the PowerShell code:

function Send-ArduinoSerial {
param ( [parameter(Mandatory=$true, ValueFromPipeline=$true)] [int[]] $byte )
#Find Arduino COM Port
$PortName = (Get-WmiObject Win32_SerialPort | Where-Object { $_.Name -match "Arduino"}).DeviceID
if ( $PortName -eq $null ) { throw "Arduino Not Found"}
#Create SerialPort and Configure
$port = New-Object System.IO.Ports.SerialPort
$port.PortName = $PortName
$port.BaudRate = "9600"
$port.Parity = "None"
$port.DataBits = 8
$port.StopBits = 1
$port.ReadTimeout = 2000 #Milliseconds
$port.open() #open serial connection
Start-Sleep -Milliseconds 100 #wait 0.1 seconds
$port.Write($byte) #write $byte parameter content to the serial connection
try    {
#Check for response
if (($response = $port.ReadLine()) -gt 0)
{ $response }
}
catch [TimeoutException] {
"Time Out"
}
finally    {
$port.Close() #close serial connection
}
}

Once the function has been loaded into your PowerShell console we can turn on and off each of the sockets, for example

Energenie-PSFunctionExample

This is one of those moments when an image fails to express the sheer excitement of a lamp going on and off!

If you forget to plug in your Arduino an exception will be thrown for example

Energenie-PSFunctionExampleError

What’s Next/Further thoughts

  • Program some keyboard shortcuts to power the sockets on and off.
  • Create a web front end and on that note I should point out that Energenie have another solution the LAN Power Management System available, this would be an easier solution for the none techie folks.
  • Try this with a Raspberry Pi

Anyways, thanks for reading my posts and I hope you enjoyed Powering Power Sockets with PowerShell as much as I did!

Regards,

jfrmilner


Previous Post 1 of 3

Next Post  3 of 3

Part 2 – Configure the Arduino with the RF Transmission Sketch for your Energenie Power Strip

Continuing on from the previous post where we collect all the RF codes for my Energenie Power Strip we will disassemble the receive circuit and build one for RF transmission.

Connect up your circuit like the below diagram

Energenie-fritzingTx

Here is a photo of mine once completed

Energenie-PhotoTx

My sketch below is a modified version of the “Examples > RCSwitch > SendDemo” Sketch included with the library. Basically the Arduino listens on the Serial port for a byte and if one is found it will check for a matching if statement and actions that code block. Each if statement has been configured for one of the ten possible codes captured earlier and also set to send back a confirmation of which code block was ran, the latter is useful for debugging.

Here is my sketch


/*
 Example for different sending methods
 http://code.google.com/p/rc-switch/
 Edit by jfrmilner for Energenie PowerStrip using Serial input
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
byte inByte = 0;
void setup() {

 Serial.begin(9600);

 // Transmitter is connected to Arduino Pin #10
 mySwitch.enableTransmit(10);

// Optional set pulse length.
 // mySwitch.setPulseLength(320);

 // Optional set protocol (default is 1, will work for most outlets)
 // mySwitch.setProtocol(2);

 // Optional set number of transmission repetitions.
 // mySwitch.setRepeatTransmit(15);

 //Serial.println("Ready"); // Ready to receive commands
}

void loop() {
 /* Switch using decimal code */
 if(Serial.available() > 0) { // A byte is ready to receive
 inByte = Serial.read();
 if(inByte == '1') { // byte is '1'
 mySwitch.send(4314015, 24);
 Serial.println("1 ON");
 }
 else if(inByte == '2') { // byte is '2'
 mySwitch.send(4314014, 24);
 Serial.println("1 OFF");
 }
 else if(inByte == '3') { // byte is '3'
 mySwitch.send(4314007, 24);
 Serial.println("2 ON");
 }
 else if(inByte == '4') { // byte is '4'
 mySwitch.send(4314006, 24);
 Serial.println("2 OFF");
 }
 else if(inByte == '5') { // byte is '5'
 mySwitch.send(4314011, 24);
 Serial.println("3 ON");
 }
 else if(inByte == '6') { // byte is '6'
 mySwitch.send(4314010, 24);
 Serial.println("3 OFF");
 }
 else if(inByte == '7') { // byte is '7'
 mySwitch.send(4314003, 24);
 Serial.println("4 ON");
 }
 else if(inByte == '8') { // byte is '8'
 mySwitch.send(4314002, 24);
 Serial.println("4 OFF");
 }
 else if(inByte == '9') { // byte is '9'
 mySwitch.send(4314013, 24);
 Serial.println("ALL ON");
 }
 else if(inByte == '0') { // byte is '0'
 mySwitch.send(4314012, 24);
 Serial.println("ALL OFF");
 }
 else { // byte isn't known
 Serial.println("Unknown");
 }
 }
}

Once the Sketch has been uploaded to your Arduino you could use the Serial Monitor to send one of the numbers or any serial aware software for that matter but if you read on to part 3 I will demonstrate doing this with an advanced PowerShell function.

This concludes part 2, I have included links to the next and previous posts below to ease navigation of this blog series

Previous Post 1 of 3

Next Post  3 of 3

Thanks for reading,

jfrmilner


Next Post (Part 2 of 3)

Final Post (Part 3 of 3)

Intro

In this post I’m going to try something a little different, I’m going to explain the process I used to control a four gang power socket with PowerShell. Now I’m only going to be sending serial commands with PowerShell as the hard work is being done by an Arduino and the “rc-switch” library but still this was a really fun project to do and one I wanted to share!

To start, you’ll need all the following items:

Bill of materials:

# Name Price Shop
1 Arduino Uno £15 Google/eBay
2 433 Mhz Transmitter and Receiver £3 eBay: search for “Arduino 433” or “RF Link kit”
3 Energenie Trailing Gang with Four Radio Controlled Surge Protected Sockets £20 https://energenie4u.co.ukwww.amazon.co.uk
4 Breadboard and a few jumper cables Google/eBay

Part 1 – Capture the RF codes for your Energenie Power Strip

To start you will need to connect up your circuit like the diagram below

Energenie-fritzingRx

This is a photo of how mine looked when completed

Energenie-PhotoRx

Like I mentioned in the intro we will be using the “rc-switch” library which can be downloaded from http://code.google.com/p/rc-switch/. Add this to your \arduino-1.0.1-windows\arduino-1.0.1\libraries\ directory and open the Arduino IDE.

Now open the “ReceiveDemo_Simple” sketch and upload this to your Arduino.

Energenie-LoadReciveSketch

Open the serial monitor, assuming everything is wired up correctly when you press the buttons on your remote the codes will appear as “Received <7Digit>  / 24bit Protocol: 1”, for example:

Energenie-COMResults

Collect each of the buttons 7 digit codes into a table so we can use them in the transmission circuit. I recommend using a table, for example:

Switch ON OFF

1

4314015

4314014

2

4314007

4314006

3

4314011

4314010

4

4314003

4314002

ALL

4314013

4314012

This concludes part 1, I have included links to the next and previous posts below to ease navigation of this blog series

Next Post (Part 2 of 3)

Final Post (Part 3 of 3)

Thanks for reading,

jfrmilner