# Hour of code

The hour of code sessions at  Gaelscoil Thulach na nÓg were a great success last week. Students and facilitators alike had great fun. Students learnt and taught each other a great deal about coding and produced wonderful festive greeting cards.

Originally the plan by Pól,  Bernie and Fiona – the session facilitators  – was to introduce the students to coding via the Raspberry Pi Scratch environment. Giving the students a feel for both the electronics and software aspects of coding. However, due to time constraints, the sessions were focused on creating a festive greeting card using Scratch.

Some of the inspiring creations exhibited included: Santa bouncing on a trampoline – presents flying out of his sack – as he bid the viewer “Ho! Ho! Ho! Merry Christmas”, Ice skating reindeer and Dublin City sleigh rides.

Hopefully we will be back gain soon to build on those sessions, maybe adding Raspberry Pi Scratch or Arduino Scratch elements to the amazing greeting cards already created.

Nollaig Shona!

# An LED Bar Graph

For This Project We are going to use the pervious circuit (see the LED light bar tutorial) to build on top off. We don’t need to change it at all, we are just going to add to it and write some new code. What we are going to make is an LED bar graph. The kind of LED display used to give feedback for things like volume control on a speaker system. For us, we are simply going to use a Potentiometer to increase and decrease the number of LED’s turned on.

Components required:

• 1. Arduino board
• 3. Wires
• 4. 8 x 220 Ω resistors
• 5. 8 x LEDs
• Potentiometer – this and 3 extra cables are the only additions to the pervious tutorial component list

So here is the original circuit from the LED light bar tutorial.

Now we add in the Potentiometer.

If thats a little overwhelming, here is the potentiometer circuit on its own.

That’s not so complex at all.

The potentiometer acts as a voltage divider, which basically means that the voltage seen on the middle pin will be somewhere between the voltage levels applied to the other two pins. You can change the voltage on the middle pin by turning the knob, but it will never go outside the bounds of the voltages on the other two pins. In the circuit above, it means that we can turn the knob on the potentiometer to get any voltage between 0V and 5V on the middle pin. This pin is then connected to our analog input (A0 on the Arduino board). The Arduino reads the voltage level and performs an Analog to Digital Conversion (ADC), i.e. it changes the voltage to a number between 0 and 1023. This is just a simple scale to represent voltage level where 0 = 0V and 1023 = 5V.

The biggest change from the LED Light bar is the code we use. Create a new Sketch and add the following:

```//Define which analog input used for potentiometer
const int potentiometer = A0;
//number of LEDs in our array
const int numberOfLEDs = 8;
// digital pins corresponding to our LED circuits
int leds[] = {2,3,4,5,6,7,8,9};

void setup(){
// loop through our digital pins to set them to Output
for(int i =0; i < numberOfLEDs; i++){
pinMode(leds[i], OUTPUT);
}
}

void loop(){
// take a reading from the potentiometer
// for an explanation of the map function, see below
int level = map(reading, 0, 1023, 0, numberOfLEDs);

for(int i = 0; i < numberOfLEDs; i++){
if(i < level){
digitalWrite(leds[i], HIGH);
} else {
digitalWrite(leds[i], LOW);
}
}
}
```

The map function takes five parameters used to map a value in one scale range to another scale. We are looking to map each LED 8 steps as values between 0 & 1023 (because this is the range of readings the Analog input can read).
The Map() function’s five parameters are:

• The current value we wish to map to a particular scale
• The fromLow value which set’s the minimum value of the scale we are mapping from, in our case the minimum value that can be read from the analog pin A0 i.e. 0
• The fromHigh, which is the maximum value for the scale we a mapping from, 1023 in our case
• The toLow which is 0 in our case as we will have 0 LED lighting when the reading is 0
• The toHigh which is 8 in this example as we want all our LED’s lighting when the potentiometer is turned up to full

Now plug upload the code to the Arduino and you should have the result shown below.

This Tutorial is based on a post on my own blog.

# An LED Light Bar

For the second project in our Beginning Arduino series I decided to build an LED Light Bar (think of Knight Rider). This will teach us some of the basics of working with multiple outputs and it will allow us to build things like Christmas light decorations. We will also gain a good foundation for working with a 7 Segment LED which we will look at in a later date.

What we need:

• 1. Arduino board
• 3. Wires
• 4. 8 x 220 Ω resistors
• 5. 8 x LEDs

It isn’t essential to have 8 LEDS/Resistors, you can have less or more you just need to have a resistor for each LED and a digital out on the Arduino.

Put all the components together as shown in the image below

In case that circuit is a little overwhelming here is a circuit with just a single LED wired up. All the other LED’s follow the same layout but with their input from a different digital out on the Arduino.

Now fire up the Arduino IDE and create a new sketch with the following code:

```void setup(){
//looping through the digital pins 2-9
//and setting the mode to output
for(int i= 2;i <= 9;i++){
pinMode(i, OUTPUT);
}
}
// Simple function to loop through all LEDs to turn them off
void turnLEDsOff(){
for(int i= 2;i <= 9;i++){
digitalWrite(i, LOW);
// wait 200ms
delay(200);
}
}

//main loop
void loop(){
// move through the LEDs lighting single led at time
for(int i= 2;i <= 9;i++){
//turn off All LEDs
turnLEDsOff();
// turn on single LED @ position i
digitalWrite(i, HIGH);
// wait 200ms
delay(200);
}
// same as above but in reverse order
for(int i= 2;i <= 9;i++){
//turn off All LEDs
turnLEDsOff();
// turn on single LED @ position i
digitalWrite(i, HIGH);
// wait 200ms
delay(200);
}
}
```

Plug in the Arduino to a power supply and There you have it, an LED Light bar.

## Issues I experienced

While doing this project I came across an issue where the last LED would not light up for me. I tried swapping LED’s, resistors and cables but found nothing was faulty. Could the breadboard of been faulty? Sort of, but not really. I basically didn’t realise the was a break in the ground rail on the bottom. So I had to bridge the break ( see the image below).

But Why did the other LEDs on the same side of the break work? Because when an IO pin is configured as an OUTPUT, and is set LOW, it is effectively connected to ground, allowing the rest of the circuit to behave as normal

Here is a video show this issue:

I based this tutorial on a post I wrote for my own blog and on the LED Light Bar project in Arduino Project Handbook

# Retro GameBox Kit

A while ago we ran a workshop in Rua Red, where the participants built their own Arduino-powered Retro games console. It was a great success; all the consoles worked and we all got a little bit better at Space Invaders, Parachutes, Asteroids and Sudoku.

In preparation for that workshop, I put in a good bit of work sourcing parts cheaply both online and locally. On top of that, we all chipped in with making up an instruction document, getting the tools we’d need together and checking that stuff actually worked. When the workshop went off so well, we got to thinking that it’d make for a really nice kit. Especially since all the hard kit preparation work was already done!

One remaining task for packaging the Retro GameBox up into kit form was the project’s enclosure. You may remember that we were using lunch boxes on the night as our console cases. Well, I recently started playing around with laser cutting, so did up a quick enclosure using http://www.makercase.com/ and added in all the mounting holes for the hardware with Inkscape.

The design files (available in the Project files link at top) are still a little rough and will definitely be improved in the future but I’m pretty happy with this as a starting point! It was made with 4mm Birch Plywood Moisture Resistant BB/BB(MR) from woodworkers.ie. We decided to go down the wood route because you really can’t get much more retro than that.

Among the changes I’d like to make are:

• Change the box design from T-Slot to Finger joints for everything but the top face, so that we can save on nuts/bolts
• Means we’ll need some corner pads on the bottom so that it sits on a level surface with no wobbles
• Our logo didn’t come out in the final DXF file, so we’d need to fix that
• Maybe some branding on the top face too

Once the design has been fixed up, we’ll get it up on thingiverse and also release the project as a kit. Feel free to comment below if you’d be interested in the kits or have any feedback/suggestions for us. Who knows, maybe this time next year we’ll be showing it on the Late Late Toy Show!

# BattleShots

Battleshots has been born… Its a drinking game based on battleships. You get 5 ships, 1X5 test tubes, 1X4, 2X3 and 1X2 test tubes. Fill those tubes with a responsible level of the alcohol of your choice. The aim of the game is to sink all your buddies ships before they sink yours! And there’s drinking. You get hit and you take a shot… ALL the fun. Anywho… Proof of the fun can be found here:

I’ve made some changes from the above to make everything symmetrical and the board wider as the slot for the upright piece in the above photo was very close to the edge and could easily break. I’ve put the files on thingiverse for anyone wanting a go: http://www.thingiverse.com/thing:561822

The design is pretty straightforward and the link covers the basics of how to put it together. In terms of assembly I thought I’d talk through some of the design. Firstly you’ll need:

• 1* 600*400mm sheet of 3mm white acrylic
• 2* 600*400mm sheets of 3mm laserply
• 8* 120mm carraige bolts (M6 I think…) and 24 nuts to do the gaps (or some tubing cut to length… that would be neater)
• A purple whiteboard marker
• Test Tubes: http://www.amazon.co.uk/dp/B005ZR5S8W/ You need 40 to have a couple of spares so 60 may be overkill
• A laser cutter

The whole thing cost around £30 (sans the lasercutter) but I think it could be done for 20-25 if you find a cheap supplier for the test tubes. Anywho I thought I would talk through providing contrast on lasercut acrylic. I thought the purple on white came out really well and was very simple to do.

Its very straightforward. Just engrave on the material and then highlight the crap out of it. Use a whiteboard marker rather than a permanent marker. In the third photo above you can see one pass. If you clean it off with a papertowel and do a couple of passes you will have a similar output to the final photo… Neat, eh?

I have since seen acrylic paint on solid engravings on transparent acrylic which looks lovely too and I must try out in the future!

# INtroduction to Edison

I’ve been playing with the Edison that I got at the hardware hackathon BedLab attended a few weeks back. Thanks to the guys from Intel for donating a few to the BedLab fund. (Full disclosure on the post, i work for Intel over in London (www.cities.io) so I’ll try to keep the gushing praise to a minimum)

Its pretty cool, out of the box its a lot more functional than the Gen one Intel Galileo and was pretty easy to get updated and up and running. I won’t go into the detail of setting it up as there was a pretty straightforward step by step guide for doing it. Broadly the steps are:

• Install FTDI driver for the board
• Install Arduino IDE with Intel addon
• Install Edison drivers

Being on the internal trial for the Edison pre release they did a good job of integrating all the tools into one installer in order to talk to and work with the board.
The drivers in particular are cool, they let you:

• connect to the device over serial (using putty to access the linux side of things),
-Transfer Arduino scripts if you want to program it via Arduino
• Access the storage on the Edison as an external drive

So pretty functional. Anywho links are here…

Getting started: https://communities.intel.com/docs/DOC-23147.

The one quirk I’ll say is that you need two USB’s to connect to a computer to do the programming, which is a little cumbersome.I set mine up and connected it to my home wifi and then just SSH’ed into it, this is where you should be at once you complete the above getting started guide.

Some other handy things to know when playing with the device. You are not limited to Yocto, the native Linux distro that comes with the board. If you like to work through Python or Node you can use their package managers to get most things working. Working with Yocto itself can be challenging for the hobbyist. There’s no apt-get for instance, which is a bit of a pain. Yocto was designed to be for robust embedded applications. Its designed to be made from source for a specific application. Its a barebones version of linux where you only load the parts of the stack you need for your application. The theory holds that the less stuff on the build the less can go wrong and the more robust your system will be.

So if you want to make a smart thermostat you can only load the systems you need, if you want to prototype something though it can take 4 hours to add that new wifi driver and build the system again from source. If you want to play with Debian on the board Emutex have released a debian build: http://www.emutexlabs.com/blog/220-emutex-release-ubilinux-for-intel-edison

The next handy thing is accessing the edison as an external hard drive. You can plug it in and transfer over any files you want. SCP also works if you want to go down that route but if you want to transfer big files or pass information via a PC easily this is a nice trick. Found the inspiration here:  https://communities.intel.com/thread/55510. Once you’ve transferred your files from the PC to the edison, the next step is to mount the drive on the Edison  itself.

rmmod g_multi

mkdir /update

losetup -o 8192 /dev/loop0 /dev/disk/by-partlabel/update

mount /dev/loop0 /update

Then if you want to reverse the process:

cd /

umount /update

modprobe g_multi

then pull the usb cable and re-insert it, at which stage the disk should re-appear on your host machine.

Finally there’s been some nice benchmarking done by David Hunt (He also has made some pretty cool photography hacks, its worth checking out his work)
http://www.davidhunt.ie/raspberry-pi-beaglebone-black-intel-edison-benchmarked/

# Cloud Infrastructures

The Edison is pitched as an enabler of the internet of things (IoT) so I thought I would talk a little bit about using the Edison as a platform for sensors. There are lots of cloud based infrastructures that one can use to send data from these devices. I’m going to stick to the Linux side of things as I’m used to operating in that environment rather than through the arduino cross compiler.

There’s actually an IoT development kit baked into the Edison, it posts to an intel backend. It seemed quick to setup, I had a bit of a play of a Monday evening to see what its like. There’s a tutorial here if you’re interested. There’s a node and C version depending on preference. In an hour or so I had an account setup and the device associated with its backend sending a virtual sensor reading. Can’t speak to its scalability/feature set but it had a shallow learning curve at the very least.

Another option is to build your own cloud storage system. At Bedlab this is becoming a bit of a specialty with with a bunch of different types of IoT style systems with various time series datastore types being made and even (feel free to correct me here guys)  3 RESTful API’s being built at this stage for various projects. Check out the following for more info:

• BrewLab backend storage and graphing
• NodeRed implementation for Treo
• How to build your own RESTful API tutorial over at http://blog.jonnie.io/creating-a-restful-api-with-node-js/ by our own Jonnie.

There’s other online based systems that can quickly be setup to do the heavy lifting for your IoT device. I’ve had a play with GERAS from the guys over at www.1248.io, its quite good, doing exactly what you need it to, reminiscent of the old Pachube system. Xively is probably the best known system. Formerly Cosm, Formerly Pachube… Its so good they named it trice. Anywho, how I’ve finished kludgening that previous sentence into my post lets wrap up. I’ll write a follow up post on playing with the Edison over Xively. Stay tuned for more .

# Turning on an LED from a Button

So you want to Learn to program and build projects with Arduino. Me too, and I want to help you learn from my experience, as I too am a beginner.

I could do the boring, pointless Arduino version of Hello Wold, Blink!, tutorial that most people start with, but it doesn’t involve enough as far as I am concerned ( it’s all already done for you), but go ahead if you feel its worth it. For me, I want to be able to interact with it.

So for my first Arduino project I want to press a button to turn on an LED. This involves 2 Arduino Fundamentals, reading input (the button), processing it in our program (an Arduino sketch) and output a result ( turning on or off an L.E.D.).

so without boring you, lets Jump straight in…

Components we need:

• Arduino
• Wires
• LED
• Push Button
• 1 x 10k Ω Resistor
• 1 x 220 Ω

First I Followed the Tutorial in Arduino Project Handbook by setting up my circuit as in the image below:

IMPORTANT:  The LED legs must be in the correct direction, make sure the Negitive Leg ( the shorter leg on the side of the flat edge of the LED) is connected to the ground and the Positive Leg ( the longer leg at the side of the rounded edge of the LED) is connected to the input pin, otherwise you will likely burn out your LED.

I then started up the Adruino IDE, available here.

Inside the sketch I added the following code:

```const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop(){
if(buttonState == HIGH){
digitalWrite(ledPin, HIGH);
} else{
digitalWrite(ledPin, LOW);
}
}
```

If you need more information about what the code is doing, have a look at the Reference page, but it should be mostly obvious, I hope.

Selected the Arduino Uno the menu: Tools > Board > Arduino Uno

Then select the Arduino Port:

• For Linux/windows Tools > Board > Comx where x is usually 3 or higher
• For Mac Tools > Board > tty.usbmodemxxxx where xxxx is some number

Then plug in the USB into your computer and Arduino and upload the code using the button as shown in the picture below

When the program is uploaded you are supposed to be able to press the the button which the program is continuously reading in the loop function and light the L.E.D. while the button is pressed….

BUT…… for me this was not the case, at least not completely. I found that when I put my hand anywhere near the circuit without actually touching the button the L.E.D. would still light up and sometimes the L.E.D. would just light up and stay on with out even touching the button as shown in the video below.

Frustrated yet? I was. So what to do when the instructions don’t work? Well for me usually I turn to stackoverflow for programming problems. So I had a look on the stackexchange which is the parent website of stack overflow and found an electronics subsection.

So I posted my issue, along with the steps I took myself to try and solve the problem (N.B.: if you go to any stack exchange and don’t show you made an effort, often you will be dismissed with comments like “have you even tried Googling it yourself”, So make the effort)

So here was my Question to the community

What I learned was that the reason the L.E.D was lighting when my hand was close to the circuit was due to ambient electromagnetic interference . As ‘Shubham’ explained to me

It’s because your button pin is floating (susceptible to ambient electromagnetic interference).

All the second resistor is doing is draining a little current from power to ground, when it should actually be functioning as the pull-down resistor for the button pin.To fix this issue I made the following change to the circuit:

I changed this:

To this:

And now the Circuit behaves as expected.

And there you go…a functional Arduino beginners project. I know some of you might be thinking “is it not a bit complex for simply turning on an L.E.D”. For that purpose yes, it is but imagine adding a few buttons, a few motors and a bit of work to the program, and it could turn into a basic remote controlled car. Or swap out the button for a light sensor and you could have an automated light that comes on when it gets dark. The possibilities are endless. But don’t worry, like you I’m a new to this too , so we can work on it together…

I based this post on a post I wrote for my own blog

# Preparation

The final prep was/is upon us! We were incredibly tight to the deadline so we’re doing this one post hoc…
Two nights of pain, misery and electronics lay/lie ahead/?. Baton down the hatches and tell your other halves you love them.

## Thursday night

Martin and Greg do science.
Martin worked on the sensor aggregation and Greg worked on the sensor box enclosure and PCB design. The PCB came out awesome. It was made using the etching process described in a related post. It is surprisingly detailed!!! Check out the close up…
For a compact package it does quite a lot! temperature, humidity and light are being measured. It is then read on a ATTIny chip and then transferred over bluetooth to a gateway device. It is, to borrow a word, the tits.

## Box enclosure

The box came out alright! Pic of drawing it up with martin during the week… I’m going to write up a post about the process separately. It was quite nice to go from an idea to a working prototype in 3 days. shows the power of modern maker tools. Anywho, the output was pretty!
It was cut in the UCL institute of making, on their super awesome laser cutter. we’re going to go through a big upload of the various parts of the design, between thingiverse and github. Stay tuned, we’ve a big lump of this to do over the coming month or so!
Plug was fun, it always facinates me the practical mechanical solutions to older technologies. I would always think of electronic solutions to problems.
The classic example is the shower (bear with me)
A shower does PID style portortional control of temperature using purely mechanical technologies. The mixer uses a 3/2 valve to mix the hot and cold.
However as you shower the hot water reduces and the cold water increases and your temperature changes. how the system adjusts for this is by including a wax in the inside of the barrel of the 3/2 valve. The wax contracts as it gets colder and shifts the valve over a bit. This increases the flow of hot water in relation to cold water and to the user maintains (theoretically) a more steady and temperature consistent flow of water.
This obviously has its downsides… The response time of the material (or its {science term for what I’m talking about}) is quite slow and cannot account for sudden reducitions in hot or cold water. This is why a flush of your toilet can scald you or someone turning on the hot tap in the kitchen makes you super cold. Anyway I digress… So 3/2 valv… Extension cords.
Its super mechanical. Taking it apart was a lot of fun and brought me back to my mechatronic roots. It was a simple fix. Remove the switch and wire in wires to each of the individual live lines of each switch. We stripped a kettle lead to get the proper thickness wire and broke our the wires through the the bottom part of the plug through drill holes. These fed into the acrylic box through the lasercut holes. This was attached to relays and hey presto, electromechanical switches that can be arduino controlled. Check out the final product:

stay tuned for github and thingiverse link ups here and feel free to comment on any suggestions for changes below the fold.
Hope you learned something about showers smart plugs.

## Friday night

[I’m tagging in the gang WWE style here as I was sleeping]

## MakerFaire Day

The weekend went really well. Got to talk to a lot of people about our open source projects and how home automation can be improved through the use of open source technologies. The stand looked pretty cool too!
One of my favourite bits of the faire was the twitter knitter from TOG. You can see our bedlab scarf on the table, it was awesome!!!
There were some other really fun projects. There was a modular music modulator box system, a turntable giant spirograph and a blacksmith.
I spent a fair bit of my time at the intel stand as it was a bit of a work trip for me. It was a lot of fun, I played the Mrs. Doubtfire for the night (sans the crossdressing (or even a reversible shirt)) managed to get over to both for much of the day. I was showing a twitter activated bubble maker. I never thought I would utter the phrase “I just can’t get my bubble machine to connect to the internet” but alas I did. It looks pretty nice though!
Anywho, that was us. We look forward to the next one… Bring it on!!!

# Treo – pure living

We had an amazing time at the hardware hackathon, leading up to the Web Summit. Thank you to all the sponsors and participants for making it an unforgettable event.

Team Breazy presented Treo, the route to healthy living. A personal pollution exposure monitor, that empowers us to make smarter and better decisions, leading to a healthier lifestyle.

The solution, made available on github., comprised:

• A wearable device and docking station designed in AutoDesk and delivered as 3D-Printed and Lazer Cut models.
• An Electric Imp engine running the docking station and RedBearLab Micro brains inside the wearable.
• The server receiving, processing and serving the information stored in a MongoDb database was built on Node-RED.
• Finally a Mobile App built on the Ionic framework presented the analysis and provided suggestions for a healthier lifestyle.

The most notable improvement from the previous hardware hackathon was the addition of a strong design element, which enhanced the form to follow the hardware functionality.

In that spirit we’d like to thank Meadhbh, Alan and Tom; the design leads; for ensuring the product came to life. Hendrik; the business lead; who put the commercial viability into the plan. The hardware leads; Jason, Conor and Greg; for producing functional prototypes. And the software leads, Victor and Martin, who delivered the mobile application and web service behind the product.

Congratulations to the winners Cash-up and here’s looking forward to the next hwhackathon and TechShop Ireland.

# Retro Gamebox Workshop – Rua Red – Digital Week

After the heady preparation work last Tuesday, we eventually got to put the plan to test on Thursday at the oversubscribed workshop, with 9 participants.

There was an eclectic audience, ranging from school kids to retirees! Some people were just eager to play Space Invaders, or rather Pacman – apologies again for not having it. Others had previously worked on the mechanical side of an Arduino project and were eager to get stuck into the the Software/Electronic side of it. Some had even hacked outdoor Solar powered lights and programmed with the Sinclair but were new to the Arduino. All in all it was a wonderful mix of ages and experience!

Five Bedlabbers: Greg, Martin, John, Mick and Victor, were at hand to facilitate the workshop, which meant no one was short of assistance or guidance throughout the project.

I am ecstatic to report that everyone got to complete their projects and go home with a Space Invaders game console or the odd Asteroids one. Most importantly though we all (facilitators and participants alike) had an amazing time and learnt a great deal.

You too can can have some Retro Gaming fun by checking out the apcmag tutorial derived from the nootropicdesign games which we updated to work with the uno. Enjoy.

A big shout out goes to Beccy and all the staff and participants during Rua Red‘s Digital Week, which was a great success!