Skip navigation
1 2 Previous Next

Arduino

16 Posts authored by: ipv1 Top Member

Abstract

As most of you know, I am doing a quadcopter from scratch project where I make almost everything from scratch. In doing so, I had to understand the dynamics behind the software/firmware and in order to explain the quadcopter, I can start by explaining a balancing robot. In this post, I explain the build and provide a video demo for the robot. Lets go!

 

The build

I usually build stuff from scrap and recycle what I can and this project is no different. I start with some scrap wood and made a simple box like frame. I trimmed off wood from the sides to reduce weight and to make it a little more presentable. Finally I added some paint and a quick and dirty job later, I have a robot frame.

IMG_20150411_201416.jpg

As you can see, in the above pic, I have some motors and wheels attached as well. I bought the wheels a long time back and the motors were purchased online. These motors are 288RPM 12V rated and have optical encoders so that we can track the distance moved by each wheel. I clamped these motors in place using some sheet metal pieces I cut up from the scrap tin boxes I had. You can use soft-drink Tins etc as a source of the sheet metal and self threading screws to attach them to the wooden base.

 

In order to drive the motors, I am using an L293D motor driver which came from an older robot which lost it's wheels in an accident.

Since we need a place to put the control board, I used a cardboard box and cut out an H shaped plane to sit atop the motor driver floor. The control board itself if an Arduino Uno which I received as a part of the Internet Of Holiday Lights Challenge from Element14 and I made a shield for the MPU9150 breakout board. The image below shows the same shield but on the FRDM K64F board which I was using for the quadcopter.

IMG_9611.jpg

I scraped together some libraries from the internet for the MPU9150 as well as PID control and a few hours of head scratching later, it actually worked! The video below shows the working robot in action.

I had some failures along the way but it was quite easy and only a few hours of work once you know what you are doing. In the next post, I will be sharing some more details on the code as well as things that you need to consider when making one yourself.

 

Cheers,

IP

Links to Previous Posts

Preface

My project for the Internet of Holiday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff. I connected them to the YUN and made the control for the Xmas Tree Dynamic and static. It is now integrated into the OpenHAB interface and the YUN works as a relay. I have made the minions dance using a DIY approach and connected them to an RPi. I also wrote a python script to get mentions on twitter and play music while controlling the minions. I also showed you the final build but not yet a video. post, I go back to the minions and make them learn MQTT.

 

Aftermath Report

The lights project has been appreciated a lot by guests and I am convinced that some future projects should be designed such that they can be showcased in our now IOT living room. My experiments with the Infineon shield will have to wait until such time when my wife will allow me to take the controller down. Hence I am preparing a IoT bench light around the same concept which can also serve as a notification system.

 

On the other side, I recently purchased a TPL ink WR740N wireless router which has the same atheros chip set as the YUN. I was successful in installing openwrt which is the same Linux district as the YUN. The absence of a memory card slot and io pins are felt but I have found the UART pins and hope to connect an Arduino Nano to it which will add future project prospects. I am currently trying to compile some basic programs for socket clients so that I may extend some functionality over the network and will update once I have something worth showing.

 

The router details

I got this TPL-Link WR740N on an online store for 800INR with version 4.28 on the label. The image below is of the router itself.

15%2B-%2B2

The antenna is non-removable and its a no thrills, no frills router. For the kind of BW I get here, this is no problem for surfing the internet.

 

Getting Linux

The Linux distro in the YUN is the OpenWRT which is available at www.openwrt.org and there is a whole list of routers supported. The current stable version is Barrier Breaker and to download the binary, go to

https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/

There is a long list of binaries which have been compiled according to manufacturer but these are all meant for the atheros ar7xx series based routers. I got the https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-ar71xx-generic-tl-wr740n-v4-squashfs-factory.… which is the latest at the time. Next to flash your router with the binary, no fancy tools are needed. Simply login to the router at 192.168.0.1 which is the default address or whatever you set it to be. In the system part, there is an option to update the firmware... so update it with the OpenWRT binary. Let it reboot and connect via the wired ethernet port since the default configuration is for the wlan0 to be down. Login to 192.168.1.1 and customize. Once you set the root password, you can start using SSH to login to the router as well. Below is a screenshot of that...

 

yQBZ1PBL4Ycs616yCCymOclhRYjpr5VqztOOyOvIByQ=w1024-h768-no

More to come

It was quite easy to get here and all it took was the right few steps. I am attempting to solder some serial port headers and will post again once I am good and ready. Hope this helps and if there are any inputs, please feel free to leave a comment at the end.

 

Cheers,

IP

 

Links to Previous Posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a

way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In this post, I do a summary of the concept, the final result and problems faced and lessons learned. Lets go.

 

The concept

 

The original concept of the project came from the fact that we have a very disorganized living room. Element14, Infineon and MCM Electronics sponsored some parts and I wanted to make them the hero of this project. Additionally iot.Eclipse.org provided some pretty nifty tools to work from. I started by drafting an idea around the Infineon RGB LED Shield and the fact that the YUN has the capability to connect to a Wi-Fi Network. Being an Electrical Engineer I am not an expert on software development and GUIs and hence I took to something that I understand which is OpenHAB. The design was drafted and the first few blogs were published around a focused plan. The target was not only to build the electronics but to demonstrate how practically the things fit into real life. And thus I began one module at a time.

 

The Implementation

 

Hence I began working with the YUN and the Infineon RGB LED Shield and in the process I did a review and to make life easier, I wrote a library for the shield. In order to control the YUN, I used kartben sir's original code and added my own twist to it so that it can received the data in a predefined format. I added some basic Low Pass Filter and connected the audio to the system and made the lights dance to the music. The lights were meant for the living room and hence me and my wife moved to make the Living Room more usable. A DIY frame later, the LEDs were up above the curtains and I hooked them up for the final build.  For the interface, I used OpenHAB to make things pretty for the user. The code is similar to Javascript without the HTML to present it and presented it to the world.

 

With the Lights functional, I moved on to create the tree which used up another arduino and the communication was established over a wire. I used RGB LEDs that can be chained together and 120 LEDs on the tree make for some pretty bright lights. I wrote the code for the Tree which I explained in my last blog and the whole thing lit up like... christmas! The tree can light up according to music or a fixed color by Software or in predefined patterns.

 

The lights and sound needed some dance. My wife and I made minions(pun intended) and I used some element14 boxes to make a crank-piston arrangement and added a motor. This made the minions dance and I wrote a blog post about it so that anyone can make it at home. Moving on, I added a raspberry Pi to the mix since my YUN was busy behind the curtains(literally). A python script later, I was able to read tweets mentions and hashtags and I used it to trigger a minion Dance whenever someone mentioned @ip_v1 on twitter with #happynewyear or #HappyChristmas. It is so much fun and there is a blog post about that as well. I also added a little MQTT to it so that I could control the minions using OpenHAB and now they sing and dance on queue.

 

The final build was completed, cleaned and documented. A fireplace was fabriacated out of styrofoam and a wooden shelf was converted into a snowy scene for the minions to stand. The shelf lights are controlled via IR Control and added ambiance to the shelf. The completed system is demonstrated in a 10minute video below.

 

For more images about the build, please visit, [Dynamic Living-Room Lights] The Big Picture - The Final Build for the graphic details.

 

The Demonstration

 

I made the video with the help of my wife and it was the first time I actually edited a video which made it a long learning process. The end result is given below.

 

Lessons learned and future work

 

I deviated from my normal 'humongous designs that spread everywhere' to a smaller more focused design this time. I experimented with the arduino YUN, python and PAHO, I reused my knowledge of OpenHAB and made the best use of Cardboard boxes from Element14 that I could and the end result was a much more presentable system than I had imagined. I plan to expand the Infineon Shield capabilities to use DMX for audio in the future and in doing so I will be able to relieve the YUN from driving the LEDS. Additionally, I need to buy better LEDs since the ones I have are not very bright even though they get the job done. IF I get my hands on a 3D printer, the first thing I need to do is make a better mechanical arrangement for the minions because the cardboard and styrofoam arrangement tends to wear out with time.

 

Conclusion

 

It was fun. I had planned on finishing the project before the holidays but I ended up doing a lot more tweaking and the final system is something that will stay in the living room as a permanent resident. The tree will also be a permanent resident as well and everytime someone asks why, we can demonstrate the system and christmas will never actually be over. I have tried to put up as much detail as possible and hope that next year someone will take a piece of this project to their living room and sends me a tweet and makes the minions sing and dance.

 

Thank you,

Inderpreet Singh

Link to previous posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff. I connected them to the YUN and made the control for the Xmas Tree Dynamic and static. It is now integrated into the OpenHAB interface and the YUN works as a relay. I have made the minions dance using a DIY approach and connected them to an RPi. I also wrote a python script to get mentions on twitter and play music while controlling the minions. I also showed you the final build but not yet a video. post, I go back to the minions and make them learn MQTT.

 

In this post while I wait for my video to upload, I explain the code for the tree

 

The problem

 

The basic issue that I was facing is the ability to connect two pieces of my project which is the YUN and the Tree together. I initially though of using a wireless route but in the end, since I needed to send a direct audio line to the tree anyways, hence I chose to use the wired approach and an old school way of doing things on it. There are a couple of methods of doing what I am doing like libraries and stuff and any suggestions are welcome.

 

The Approach

 

My approach was to build in two steps.

Step 1. Build the communication

Step 2. Build the activity functions around the communication.

I will briefly explain the code for both in the next few sections.

 

The communications code

I built the communications part on top of the serial interface of the arduino. I generally use the interrupts system in any microcontroller since it makes sure I 'don't wanna miss a thinngg'(-Aerosmith). Sorry about that pun.

Anyways I start with the example code on the arduino and I use the Serial Event example

 

String inputString = "";        // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete







void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}


void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}


/*
  SerialEvent occurs whenever a new data comes in the
hardware serial RX.  This routine is run between each
time loop() runs, so using delay inside loop can delay
response.  Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}






Here you can see that there is a function called serialEvent() which executes automatically every time the arduino receives a character. There are two global variables that can be accessed from anywhere in the arduino program where we save the received string and a notification flag that a string was completely received. BUT I don't need that so I start by deleting way the code in the functions and write my own.

 

The serialEvent is supposed to be triggered everytime I get a single byte over the UART and hence the code becomes something like...

 

void serialEvent() {
  while (Serial.available()) {
      // Read a char
      char inChar = (char)Serial.read();
      if(inChar==':'){                        // Start New Frame
          memset(ptr, 0, FRAMESIZE);
          inFrame=true;
          myIndex=0;
      }
      if(inFrame==true  && myIndex<FRAMESIZE){ // Add a byte
            *(ptr+myIndex)=inChar;
            myIndex++;
      }
      if(myIndex==FRAMESIZE){
          inFrame=false;
          if(inChar=='#')
            memcpy(&myFrame, ptr, FRAMESIZE);
      }
  }
}






 

In my code, I have a global flag inFrame which tells me if I am in between frame receives. The reason why I have it as a global and not a static is because I later want to implement a timer and a time out which means that if it takes too long to receive a complete frame then prolly something is wrong and I need to discard the data because something went wrong.

In this code I simply wait for ':' which is my start of frame and then use memset to initialize the space with 0s and set some flags. In the next iteration, the function will be 'inFrame' and hence it will copy the data to the memory. I understand pointers so I just use that instead of the dozen other methods. I also check for my maxFrameSize since my protocol has a fixed frame size. I can use a variable frame size too but maybe some other day.

In the end if the received data matches the frame size, we check for the endofframe which is a '#'. Everything in between can be a ascii character or anthing else but our code does not care about that. The question is what is that pointer pointing to?

 

The protocol

 

I made a structure for my protocol and it's quite simple.

struct sFrame{
    char cStart; // Expect :
    char cMode;  // A-Audio, M-Manual with RGB, P-Pattern
    char cRed;
    char cGreen;
    char cBlue;
    char cEnd;
};

As you can see that there are char type variables for everything. These can be replaced but again not our motive right now. In the global space, I do the following.

 

struct sFrame myFrame, buffer;            // Object to store the frame
char *ptr = (char*)&buffer;      // Point to the object

 

This creates an object without using the heap (malloc) since I will need a fixed size throughout the lifetime of my system. Next I create a pointer to this buffer BUT cast it into a char type. This makes sure when I ptr++, I jump to the next char in my structure. Easy! But how do I use this?

 

The Loop

 

The code for the loop is given below.

 

void loop() {
  // print the string when a newline arrives:


  if(myFrame.cMode=='A'){
      //Serial.println("Audio Mode");
      hue0 = constrain(map(analogRead(channel), 0, 400, 0, 255), 0, 255);  // Read Audio
      uint32_t color0 = Wheel(hue0);
      //Shift the current values.
      for (i = 0; i<NUMPIXELS; i++){
          data_array[i+1] = data_array[i];
      }
      data_array[0] = color0;
      for(i=0; i<NUMPIXELS; i++){
          pixels.setPixelColor(i, data_array[i]);
          pixels.show(); // This sends the updated pixel color to the hardware.
      }
  }else if(myFrame.cMode=='M'){ // Manual mode
        for(i=0; i<NUMPIXELS; i++){
          pixels.setPixelColor(i, pixels.Color(myFrame.cGreen, myFrame.cRed, myFrame.cBlue));
          pixels.show(); // This sends the updated pixel color to the hardware.
      }
  }else if(myFrame.cMode=='P' && myFrame.cRed==0x00){
        rainbowCycle(20);
  }else if(myFrame.cMode=='P' && myFrame.cRed==0x01){
        colorWipe(pixels.Color(240, 0, 0), 200); // Red
        colorWipe(pixels.Color(0, 240, 0), 200); // Green
        colorWipe(pixels.Color(0, 0, 240), 200); // Blue
        colorWipe(pixels.Color(240, 240, 0), 200); // Red
        colorWipe(pixels.Color(0, 240, 240), 200); // Green
        colorWipe(pixels.Color(240, 0, 240), 200); // Blue
  }
}

 

In this example, I use the functions from Adafruit's NeoPixel Library to implement the patterns. When in the loop, I check for the mode settings. If its A then so something and if M then do something and if P then do something else. The serial interrupt takes care of serial communication in the background. Since I have created simple objects for the structure hence I can access the member functions with the . operator. Nothing to it.

 

Conclusion

I wanted to write a short article to explain the working of asynchronous events on a microcontroller and here it is. This is the simplest possible implementation and you can expand it as you like. There is no library code size since there is no library and I hope you got something while reading this. Any suggestions are most welcome and I if you do a project and use any snippet, just say Hi in the comments.

 

 

Thanks,

IP

 

Link to previous posts

 

Preface

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff. I connected them to the YUN and made the control for the Xmas Tree Dynamic and static. It is now integrated into the OpenHAB interface and the YUN works as a relay. I have made the minions dance using a DIY approach and connected them to an RPi. I also wrote a python script to get mentions on twitter and play music while controlling the minions. I also showed you the final build but not yet a video.

 

In this post, I go back to the minions and make them learn MQTT.

 

The problem

paho_logo_400.png

The basic issue I had failed to address was the fact that I had used a simple script to read tweets and make the minions giggle. I wanted there to be a way to trigger the minion dance via my web interface which is built on top of OpenHAB. There are a couple of ways to do this like remotely invoking a bash script etc but I thought since its MQTT time, why not? Hence I started looking at Paho for Python and this post turned into a tutorial for implementing MQTT Communication in a simple project. Lets see what we can do.

 

The Design

Now I come from a single threaded microcontroller world where you do just one thing at a time. If you want to do multiple things, you need to write a simple scheduler using a timer and I have done this for ages. Yes there are a lot of ready solutions out there and some lite RTOS as well, but I like to know my code size before the compiler and hence I have written my bits of schedulers(some times in assembly) for over a decade. Python can do a lot of this stuff on it's own so it was time to let google guide me. I needed a destination and my version of a design is shown below.

 

dea717c403e0f18fb7852509e3af1332.jpg

 

Hence its clear that since the MQTT Message can arrive anytime and my minion animation is around 45seconds, I need to get the messages in a separate thread. So how exactly does one do all that?

 

The Implementation

The implementation is simpler and the code in Template form is given below.

In order to install paho on the RPi, I executed the following commands in succession...

 

sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install paho-mqtt

 

 

Alternatively, You can...

wget  https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python get-pip.py
sudo pip install paho-mqtt

 

Alternatively you can build from source and the instructions are given at https://pypi.python.org/pypi/paho-mqtt I use setuptools in windows as well so the first version was the simplest for me.

 

Next the actual script. I wrote a template for future projects and it looks like...

 

#! /usr/bin/python

import paho.mqtt.client as mqtt
import time

#Global Stuff
Flag=0
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
#Tell python to look at the global variable Flag
global Flag
Flag=1
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("/TheTopicIWantToListenTo")

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+": "+str(msg.payload))

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect("iot.eclipse.org", 1883, 60)

#Start Loop
client.loop_start()

try:
     while True:
          if(Flag==1):
               print 'The Flag was set! Woohoo!'
               Flag=0
     print 'Doing Something Here'
     print 'Sleeping again'
     time.sleep(30)
except:
     print 'I made a boo boo'
finally:
     print 'All Clean up Now'
     client.loop_stop()
     # GPIO.cleanup() anyone?

 

The code is self explanatory. The try and except and finally are used to execute cleanup code which is a good practice in my mind. This can be used in your next project and I hope it gives the newbies a better place to start.

 

Conclusion

There are N number of ways to do something and I am still learning. I just wanted to share this little snippet and I hope it is useful. Please feel free to add something to the above if you feel it.

 

Cheers,

IP

Link to previous posts

 

Preface

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff. I connected them to the YUN and made the control for the Xmas Tree Dynamic and static. It is now integrated into the OpenHAB interface and the YUN works as a relay. I have made the minions dance using a DIY approach and connected them to an RPi. I also wrote a python script to get mentions on twitter and play music while controlling the minions.

 

In this post, I finally explain the bigger picture and the completed layout of the whole system.

 

Redoing some things

 

Many times it becomes essential to redo things in a project because of unforeseen circumstances but in my case it is mostly due to an uncontrollable urge to tweak things. Just like the motor for the minions had to be replaced, the final build had to be modified as well. I will simply go though each component in brief and it's installation for the final build.

The IoT Tree

The Tree has been explained in some detail in my previous post [Dynamic Living Room Lights] The XMAS Tree and in the living room, it was placed in the opposite corner so that it lights up a part of the room. The image below shows the placement and since the data transmission takes place over a serial link, I took a four core wire and laid it out 'inside' the wall. This way I use up three wires- GND/Common, Audio-In and Serial In.

ff4432562f7289df0c2385b8d6fbacf3.jpg

3e17169b648ffe5e078a054887aaace2.jpg

 

The length of the wire was increased and hence I had to drop the baudrate to 9600bps. I was lucky and it worked otherwise I would have to use something like modbus to talk to the remote. I was contemplating the use of the fourth wire for 5V since everything works off it, but I did not want unnecessary voltage drops messing with system operation. 120 leds suck up some current and their blinking causes spikes so I use a 1Amp SMPS for just the tree.

 

The Moodlights

These did not really get relocated, I just added a little extra wiring from the RGB LED Strip to the Infineon Shield. Image below shows the same.

1c0ab5c048e7a507af409c24ebd87861.jpg

I had to go out of the house for that wire... The LEDs themselves look good but the quality of LEDs is a bit questionable. I bought some RGBs 10MM lamps and will experiment with them before making any comments on that.

cddfcf7dc9211c1e323c52b5601f6023.jpg

That looks good.

 

The Controller YUN

The YUN performs two functions in my project- It controls the Curtain lights and the Infineon Shield AND it acts like a relay by talking to the MQTT Broker to get commands and sends them to the remote XMas Tree. I need to put it somewhere near the Curtain lights because the LEDs are to be switched ON and OFF at high speeds and lengthly wires can cause issues- for lighting, I am not so sure but for HF communication I am sure. Hence I decided it would be best to just keep it short and so I mounted the YUN and the Infineon Shield with the Filter Circuit in the corner. I wanted to make a case using plexiglass and glue like I did for the BeyondThePhone challenge, but right now I have a slight fear of my electric saw due to a recent accident and hence I will skip that. Hopefully, I will be able to 3D print cases for my next project.(hint hint ) My wall mounted solution is shown below.

62c5912d00947a819fa6297fb874f177.jpg

It is mounted crooked due to the curtain wires being shorter that they should be(my bad). I intend to complete this box at the earliest and with some better connectors too.

 

The Minion Shelf

One of the things that makes the whole setup unique is that the lights need not be taken down. For the tree I would image taking down some ornaments but the tree and its' lights will stay there. More inconspicuously, the minions will stay on the shelf waiting for a command. Now in my previous post, I had exposed the twitter capability which enables me to trigger the Minion Dance on the getting a mention tweet with a keyword. Additionally, I have in my OpenHAB system, a button which can be used to trigger the same music and dance action manually. This makes for a fun demo for visitors and is a good conversation starter.

My wife put things together in a more presentable fashion as shown in the images below.

a1b2ab4ca353aeb67d0356c6f6597547.jpg

afd9aa454eee0f7abd0065c864d6ed31.jpg

efaaf50a50a7f0d90696e24074b1ba83.jpg

You can see there are RGB LED strip at the back which are controlled via IR. The IR remote can control the lights and I will demonstrate this in a later video but these can also be controlled via OpenHAB.

 

Once everything is in place, I can finally take a look at the bigger picture.

 

The Bigger picture

So its time to look at the final build. First a look at what was...

8c1365e679f6a1171aaf4c3f15802016.jpg

From that to...

76acfa8bbd40a576b8746d39a5182bcc.jpg

and with only the curtain lights,

7d271075c5b11ecc0298cabb32abed6e.jpg

The Infineon RGB LED Shield Drives these and does a pretty good job too.(More in the Video in the next post.)

IMG_9397.jpg

It is clear how both the light have a unique effect on their respective parts of the room. If both are combined in OpenHAB, the result is...

c9136eca6e99ad4017c016a95ebdb671.jpg

The blue cold adds a cold mood to the room which is what the mood lighting is supposed to do. Success! More than that, the sound and flickering lights combo create a Disco Mood and I have a video in the next post to show that.

I did not think that the curtain lights would be enough, but actually they work quite well. I am running them within limits so as not to damage them. Once the challenge has ended, I will further experiment with the shield's capabilities especially the DMX interface.

 

The Software

I love using OpenHAB. It gets things done quicker and I like it so much that I have one RPi running it 24x7. I have explained how to create an interface using OpenHAB in a previous post and my current menu for the YUN is shown in the image below.

9ed7d5482ee311d054f289d8f0a6e311.jpg

The First Item is the color picker which is used both any and all items in manual mode. The MoodLight Mode selects either Manual (with color picker support) or Audio Mode(with direct audio influenced color change). The next item is the Tree Light which has four modes; The manual and audio are same as before and the additional P1 and P2 are pattern modes for predefined patterns. The fourth item is the Shelf lights switch which is used to turn the lights ON or OFF. These are pre-programmed with a sequence and can be replaced with any kind of lighting scheme. The last button is to make the Minions dance by pressing a button. Simply press the button and see them wiggle their' hiney!

 

That's it for now. Hope every one likes it.

 

Cheers,

IP

Link to previous posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic. I also made a XMAS Tree with LEDs and some stuff.

 

In this post I add a minion element to the project. I had initially planned to have a Santa Claus ring his bell everytime someone wishes me on twitter, but santa is busy and I have minions...

 

Getting Minions and assigning them positions

Now minions don't exactly submit their resume via email and the ones I have a pretty lazy hence I embarked on a long journey to... Well actually I had my wife make some We had two types of minions where the first type were lazy and wanted to enjoy the party by the fireplace. These were handmade by my wife and were featured in a previous blog. The second type were party type and I printed them out and cut out the outlines. Making these minions dance was a challenge since they needed some 'support'. Now I don't have a fancy 3Dprinter(hint hint )so I resorted to what I did have and that was a lot of empty element14 cardboard boxes. And thus began my evil plan to make the minions work overtime. Muahhaa ha ha! Take a look.

 

I took apart the cardboard boxes for raw materials.

903c742fc9f2065998315eb4913098a6.jpg

Next I used a stapler and a knife to make a prop.

b6d58bbfa37eed95aa99e223f7301135.jpg

 

Next I added some mechano part from an earlier experiment. These were quite cheap 10years ago when they were presented to me. Thus my CAM and PISTON Design began to emerge from the fires of mount cardboard.

9bf504ac1629d9fef286e226ceb83a25.jpg

The minions stood by and I used glue to MAKE them participate in my experiment. Their styrofoam spines stuck like... styrofoam!

9139616cc99b8373c11be1b3417bb32f.jpg

Laughing gas..!

aa9ea315d7552e66551f5eef5402a9d1.jpg

And lastly an old toy that was relieved of it's limbs, became useful again!

5ef6dd7e03f6642ca8de9659f19f6e77.jpg

 

With that, now I have minions that dance at will.

 

Epileptic Minions -

Disclaimer! No minions were harmed(without consent) in the making of this project. The minions do dance but since the mechanism is made from material that is not stiff enough, it tends to cause... kind of epilepsy in the minions. The motor and gear system I use is from a discarded toy and due to it's gear-ratios and placement of cam, the whole thing pulls around 300mA when working. See video below.

Its clear that its not perfect and a better mechanism would solve the problem. The reason why I did not use a servo motor is because I don't have any. I got one which I used for the minion bot for the 'forgetmenot' challenge. But it works and I am willing to admit that my minions dance bad, but they can dance.

Unfortunately, the geared system sucked up too much power and it broke down a few days ago. Hence I went out and bought out a geared motor and after a little DIY magic, I got the arrangement shown below.

3c6f760a1928a323f4e34c099b9ec138.jpg

 

Moving on to the control part...

 

A simple motor switch

The minions dance when a small voltage is supplied to the motor. This I need to control via the raspberry Pi. Why not the YUN? I will that part explain later. For now, I need to make a small circuit that enables me to connect a small motor to the raspberry pi. The input signal is from the raspberry pi and the motor runs on 5V. The new motors draw around 100 -175mA at 5V which is not bad and I made a little transistor driver which can work as a switch. In order to control the speed, I simply added a 1K present between the motor and the transistor. That should enable me to calibrate the speed without messing with the PWM module. See, I took care of the simple stuff in the simplest way! The circuit is shown in the images below.

5a89dff8888204e8d13d905ce0f2d322.jpg

 

The speed is adjusted and it looks a little better than before. How better, you be the judge of that but this is the best I could do. Now to control it via the RPi

 

Raspberry Pi program to control the motor

In order to control the motor, we need to write a program to toggle the GPIO which is connected to the transistor. This can be done in a number of languages but I chose python. This is relatively simple and there are lots of tutorials on the internet for this part. I wrote and tested some code and it is given below.

 

#! /bin/python
import RPi.GPIO as GPIO
import time


#setup the Pin for the control
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, false)


#loop the loop
while(True):
    GPIO.output(18, true)
    time.sleep(10)
    GPIO.output(18, false)
    time.sleep(10)







 

This works and makes the minions dance for 10 seconds and stay still for 10 seconds and repeat.

 

Getting Tweets with Python

In my initial proposal, I wanted to have Santa ring his bell to greetings published on twitter with me mentioned. In the present case, I would use them to make the minions dance. Easier said than done and there are a number of tutorials out there about accessing twitter and the like using python. In my case, I wanted the tweets with hashtags like #happynewyear and #happyholidays etc to trigger the actions. I want only tweets with mentions to me @ip_v1 on twitter which can be accomplished a number of ways. This would involve reading the twitter feed and finding mentions and then searching for hashtags. If one is found, then the action is to be initiated. Additionally some record of the hashtag must be retained so as to distinguish between redundant instances. In my experiments, I tried do thing by many methods where the timestamps were grabbed and a few other hoops but at the end, I found a simpler method that just works.

 

Say hello to Temboo

Temboo is an online service that allows you to generate code for IOT applications in a variety of languages and devices such as CC3200 and the Arduino YUN. I used it to generate code to get tweets with mentions in python. The tweets are received in JSON format but for my solution I don't care about that. I simple use the find function

 

#! /usr/bin/python

from temboo.Library.Twitter.Timelines import Mentions
from temboo.core.session import TembooSession


import json
import re
import time

#Some global stuff here
prt_dept=50 #dept of fingerprint characters
finger_print = 'NULL'
keywrd1 = '#happy'


# Create a session with your Temboo account details
session = TembooSession("inderpreet", "myFirstApp", "XXXX")


# Instantiate the Choreo
mentionsChoreo = Mentions(session)


# Get an InputSet object for the Choreo
mentionsInputs = mentionsChoreo.new_input_set()


# Set the Choreo inputs
mentionsInputs.set_AccessToken("XXXX")
mentionsInputs.set_AccessTokenSecret("XXXX")
mentionsInputs.set_ConsumerSecret("XXXX")
mentionsInputs.set_ConsumerKey("XXXX")


while(True):
    print '\n#######################\nWoke up!'
    #Code to get the mentions


    # Execute the Choreo
    mentionsResults = mentionsChoreo.execute_with_results(mentionsInputs)
    response = mentionsResults.get_Response();


    #My work begins here
    #Mentions are now in response so convert to lower case
    resp_lower=response.lower()


    #match string1
    index1=resp_lower.find(keywrd1)


    #IF we find a match, then
    if(index1>0):
        #get new fingerprint
        new_fingerprint = resp_lower[(index1-prt_dept):index1]


        #Compare Fingerprints for new and if it IS then...
        if(finger_print!=new_fingerprint):
            finger_print=new_fingerprint;
            #Do the required action here
            print 'Found New Mention'
        else:
            print '\nNothing New'
            #else Nothing
    #Sleep for 1 minute
    print 'Sleeping...'
    time.sleep(60)

 

This code works out and I have commented it for anyone who wants to modify it for their use and if you have a better way of doing this, please do let me know.

 

Putting it all together

Once I put together the code as well as the mechanical structure, the whole thing works. Below is a video demo for documentation purposes.

 

At this point I am almost done with my project but I need to complete the documentation for the actual living room. I hope to complete that tomorrow. A lot of time and energy has been put in to make this project and I hope everyone likes the results.

 

 

Cheers,

IP

Link to previous posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts and give a preview of the system setup. I explained the Library I made for the Infineon Shield as well as the implementation for the MoodLights and made them Dynamic.

 

In this post I explain the placement of the Xmas Tree and how it fits into the living-room. The primary issue that plagues every holiday is that it goes away. I know a lot of people feel like the holidays just go away when you switch off the Xmas Tree. If only there was a way to keep the Xmas tree a part of the living room...

 

 

The tree that was... How to never leave Christmas behind!

 

I started with an artificial tree thats completely blank and had some bald spots. We bought some ornaments and stuff and made some of our own as well but the challenge was to light it up such that it can be reused. The whole concept of dynamic lighting is that you do not need to take down the lights completely. Trees seem awkward in the living room out of season and I needed a way to make the tree stay and become a permanent part of the living room. Now thats easier said than done and there is not much you can do to really make the tree look normal after the holidays BUT we can make the tree a little more dynamic. Once the lighting becomes part of the entire room and not just static lights that do nothing, we can take out the ornaments and make the tree as part of the home decor. That way the tree remains and the lighting change converts it into another living room decor or much much more. Lets see how we can do that.

Our tree initially looked like as shown in the image below.

d4f19e2701c44745c83a80daabcb94d5.jpg

 

Xmas Magic later....

I did an entire post about [Dynamic Living-Room Lights] Build Blog - Setting the stage and the result was a corner of the room which had a fireplace and a handsome tree.

745d407d79b54f52b0001f64d0cab059.jpg

The lights seen here are RGB LED strings and I used a total of 120 LEDs in this instance! They are the same as the NeoPixel from AdaFruit but I bought these from SeeedStudios. They have a single data signal connections along with a power and ground and that's it! The ornaments are a mix of bought outs and handmade ones. My wife makes some pretty cool santa minions The gift boxes are empty element14 and Wurth Electronic boxes which I have accumulated over some time. Controlling the 120 lights is a whole other ball game. Lets see what it takes.

 

Tree Controller

 

A lot of people would say that I can use the YUN to control the lights directly but instead I had to use an arduino UNO/NANO for this task. There are two reasons why we need a separate tree controller.

 

The First Reason is that the YUN is expected to control RGB LED lights in accordance with the music being played. This means if I do anything else, it will cause additional delays and the whole effect will loose it's glamor. I can use an analog circuit for the lights and equalizer but the Infineon Shield will be kicked out in that case.(DMX512- Next time baby!) Hence I need a dedicated controller for the tree lights.

The Second Reasons is that I have 120 LEDs which means that the neopixel library has to send a LOT of data on the wire which is a slow process. If I want to do something dynamic with the Lights then the code size will also be limited.

With that said, I resorted to making a individual controller for the Tree. The initial design used a wireless connection to send commands to the tree controller but I wanted to save some cost hence I resorted to using a wired USART connection. The image below shows my DIY Tree Controller in all its' glory.

1bc2e2381d987e14b955941b12def032.jpg

The circuit and code is almost the same as the one by @sciguy14 with the difference that the tree again has Three modes  at the time of this writing.

 

Connectivity

 

The arduino YUN has an AVR who's UART is connected to the Atheros Processor for communication which means no hardware UART. The UART on the USB is an enumerated type which means its only USB. The possible solution is to use a softserial which is to generate serial timing via software. The available libraries use timers and stuff which I don't need. Hence I wrote the TX part in software myself because I don't need the RX anyway. The communication is one way for now and my code uses no timers or interrupts and saves me some space too. I verified the timing using my tektronix scope which came in very handy!

33a12c3bc4484106fc5e8099065d0564.jpg

I also have a bus pirate which allows me to test some other serial stuff as well.

 

The YUN can hence transmit via Bit-Band UART and the NANO can receive it over it's hardware UART. The YUN gets all the commands for itself as well as the tree over MQTT. I wrote a small protocol for sending data. In my experiment, the frame is a follows.

1. : - Start of Frame

2. I - Infineon Settings OR T - Tree Settings OR S - Shelf Settings (More on this later)

3. A - Audio Mode OR M - Manual Mode OR P - Pattern Mode(More on this later

4. R2 - Red Hundred's Value

5. R1 - Red Tens Value.

6. R0 - Red Ones Value

7. G2 - Green Hundred's Value

8. G1

9. G0

10. B2

11. B1

12. B0

13. # End Of Frame

 

Hence if I want my tree to glow white, I would send

:TM255255255# and that would make the YUN send a command to the Tree controller automatically. And if I want the infineon RGB LEDs to turn off, I would send

:IM000000000# and that will make the YUN send an OFF Command to the Infineon Shield.

 

The static mode

In the static mode, the tree controller receives color information and command over the serial port which makes the entire tree of the same color. This is particularly effective if I want the tree and ambilights to be of the same color. The color is selected via the OpenHAB color Picker as shown in my previous post at [Dynamic Living-room Lights] The YUN talks to OpenHAB

 

These lights work quite well but I needed a separate power supply for these which I did and it did and we all did!

 

The Dynamic Mode

In the Dynamic Mode, the audio feed coming in which makes the colors on the tree lights change accordingly. The circuit and code for this part is the same by Jeremy Blum in his tutorial and allows the whole tree to act like a graphical equalizer. I did a small video to explain the system till this point and is given below.

 

 

Beware of Bugs

I got the whole thing to work like I wanted it to but after some minor hiccups. If you want to make one of these, I suggest not making the string longer than 60. I had to reduce the clock speed to 400KHz for it to reach the entire 120 LEDs and that too was not very fast. I would recommend giving shift registers a shot at this point for the desired 'wave' effect. I will experiment with DMX512 and this configuration and will have a post in the future.

 

What Next?

I will be presenting the video demo in the final summary post and will try to setup a live video feed for the project which I will keep live for as long as possible. The next post is going to have a mood light shelf which I prepared and I will go through controlling it as well. Till then...

 

Cheers,

IP

 

List of previous posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts.

 

In this post, I will explain the control of the RGB LED strips attached to the arduino YUN and connected to an instance of OpenHAB. This instance of OpenHAB is running a raspberry Pi and an MQTT broker.

 

Installing OpenHAB and Mosquittoe

 

For the Forget Me Not Challenge, I used OpenHAB as the center piece and details can be found at

 

The "Forget_What ?" project - Index

 

I did various tutorials on installing and using OpenHAB and I suggest going through them if interested. Once you have installed it, you can install addons for such as MQTT etc. Additionally, I installed Mosquitto MQTT broker but you can use iot.eclipse.org:1883 . My reason for installing a local MQTT broker was the ability to work in the absence of an internet connection.

 

1.png

Configuring the YUN for MQTT

 

Benjamine Cabe did an excellent post at Controlling Holiday Lights using MQTT and the Arduino Yún and the code is available on github. For my experiment, I changed the subscribed topic according to my requirement. The rest of the code is more or less the same. The code can be downloaded at https://github.com/kartben/internet-of-holiday-lights

 

Once you have setup the YUN with the code and into your network, you can open up a serial monitor in the Arduino IDE by pressing Ctrl+Shift+M

 

You will also need a program to test MQTT off the bat. I choose MQTT Lens which is a Google Chrome Addon. Point it towards the MQTT Broker and you should be done.

 

1.png

The screenshot above shows how to control the YUN with the code supplied by Benjamine Cabe as is. Just send RGB values and you are good. If you send 000000 then the LEDs switch off and if you send ffffff then the LEDs turn on full brightness hence the white color.

 

Now you should be able to see the results almost instantaneously and if you don't try and see if the YUN is connected to the internet or not. The serial monitor can help you debug that.

 

Making OpenHAB talk to the YUN

 

It took me a little while to get this up and I am not completely happy with it, but its a goog start for the lazy man. The task is to format the MQTT messages just like Cabe Sir's application reads so we can use the YUN Code directly. Its actually quite easy.

 

The first thing we need to do is create an Item in the .Items file. This just creates a place to house the data for OpenHAB. I created a simple item as follows.

 

Color      Hue                      "IP Hues"                                      <colorwheel>      (All)
String            HueMqtt                  (All)            { mqtt=">[eclipse1:ip-led:command:*:default]"}







 

Note that I have a color wheel object that can store the RGB values and a string object that will store the string to be passed to the YUN. The '{' indicates that a binding has been employed which is mqtt. > specifies that the direction is outwards. eclipse1 is my name for the MQTT connection configuration stored in the openha.cfg file  and ip-led is the topic. You can change this to match your topic such as /IOTLights/LEDs1 etc. Please note these are case sensitive. Next it will send whatever (*) command this object gets. You can specifify conversions here using XLS but I choose to do all that in the rules segment.

 

The second thing we need to do is make it a part of the UI. You can see there is a segment in the above screenshot for the IOT Holiday Lights and is labeled YUN. To make that, we use the following code.

 

sitemap demo label= "Main Menu"
{


// All my other stuff//
// IOT Holiday Lights Frame
Frame label= "IOT Holiday Lights"{
            Text label= "YUN" icon= "yun "{
                  Frame label= "Yun Control"{
                        Colorpicker item= Hue icon="slider"
                  }
            }
      }
}







 

I downloaded the icon from the net and put it in the OpenHAB/webapps/images/yun.png . The resulting sub frame is shown below.

 

1.png

 

1.png

So now we have a color wheel. Brilliant!

 

The Third step is creating rules to connect the Color Wheel to the MQTT topic via the String. This is where all the fun stuff happens and for my instance my code is given below.

 

 

import org.openhab.core.library.types.*


// Stuff for the IOT Holiday Lights
var HSBType hsbValue
var int Brightness
var String redValue
var String greenValue
var String blueValue


// ********************* IOT Holiday Lights ****************************
rule "YUN Lights MQTT"
when
      Item Hue changed
then
      hsbValue = Hue.state as HSBType


      val Red1 = hsbValue.red.intValue
      val Green1 = hsbValue.green.intValue
      val Blue1 = hsbValue.blue.intValue

      redValue = Red1. toString(16 )
      greenValue = Green1. toString(16 )
      blueValue = Blue1. toString(16 )

      val Tmp = redValue + greenValue + blueValue

      sendCommand(HueMqtt, Tmp)
end







 

The rule can be named anything and I created some variables globally in case I want to use the values somewhere else as well. When the item Hue changes, we extract the color values after converting the object's state to HSBType. The color values are extracted as integers and I use local variables for some experiments later. Lastly, we convert them to strings but of base 16 since Cabe Sir's code reads hex values only. Club them together and send them across. Thats it!

 

It works as is and I tested it out with the same YUN code.

 

1.jpg

 

More to DO

 

At this point I am not very happy with the way messages are sent on MQTT. I am used to writing more lower level protocols but here I need to extend the use of MQTT to send elaborate commands to the YUN which will in turn control some other things. At the time of this writing, I have already made changes to the above code and only documentation remains. This post will complement kartben '  post and will use OpenHAB to control it out of the err.. github.

 

Comment if this helps you.

 

Cheers,

IP

Link to previous posts

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system.

 

For this post, I explain how I setup the living room stage from scratch.

 

What was

 

The image below show what the living room looked like when I had applied for the roadtest plus. It had a lot of work to be done and we were missing some bits and pieces. I had planned it but executing the plan was a lot harder than I thought.

 

2014-12-04 16.36.42.jpg

 

And so be begin

 

As you can see there are a lot of unwanted elements that would not be very 'welcoming' and hence the first thing was to dispose of the additional bit. The wooden TV stand and messy corner needs to be cleaned hence I started by removing everything.

 

IMG_20141220_151038.jpg

The wall seems pretty dull and gloomy and the whole thing wont work with just lights. We need a better setting so I went out to look for something to make things better. I found PVC sheets that can be used for the wall and I could fit them pretty easily. No paint or anything necessary hence me and my wife took a day out to set them up. We also bought a tree and I order a wooden wall mounting rack which I setup on the wall. My better half decided to demonstrate her skills with Styrofoam and cardboard to fabricate a fireplace.

a.jpg

 

The result was mocked up in the cold of the night as...

 

b.jpg

 

It looks better but we want it to be a lot better. My wife put some thought into it and...

IMG_9194.jpg IMG_9210.jpg

 

output_4ja5gI.gif

 

We setup everything but the christmas tree was a bit empty. I bought some decorations and we made some our own as well. Since we are minion themed hence it seemed fit to make our minion ornaments.

 

20141222_212601.jpg

 

 

 

 

The minions ornaments were made by hand my my wife as seen in the above image and the final result is...

 

IMG_9261.jpg

and..

 

IMG_9263.jpg

 

With that the stage is set and ready for the electronics side... In the next post I will detail the making of the electronics for the tree.

 

IMG_9233.jpg

 

Documentation is taking a lot more time than I thought but I will try and document as much as possible so that you can setup things at your end as well.

 

Cheers,

IP

List of previous posts

 

The Teaser

The project documentation is taking forever and I will release it much more systematically. For now, here is a small video of one of the parts which is the audio controlled LED lights. I am using the ARDUINO RGB LED SHIELD, XMC1202ARDUINO RGB LED SHIELD, XMC1202 and an Arduino. I am using an analog filter and the details will be released in an upcoming post.

 

 

Cheers,

IP

List of related posts

 

 

The Post!

In my previous post, I had reviewed the Infineon Shield. In this post I just want to present everyone with a christmas present. I converted the Sample Code from the Infineon site into a library and its available for use by anyone. I also provided an example program to get started and I forked some code from Peter Oakes' Post as well but the colors did not match for me so I will tweak it later. Without further ado, the code is available at:

 

https://github.com/inderpreet/infineonrgb_shield

 

The download the zip into the libraries folder of your project and restart the arduino IDE. The library should appear along with the example code.

lib.jpg

 

I have abstracted the functions and have tried to make them human usable.

 

Hope this helps!

 

Happy Holidays Everyone,

Cheers,

IP

List of related posts

 

 

Prelude

LED stands for Light Emitting Diode and it is a Semiconductor Device which when forward biased, produces light. The LED is predicted to replace all light bulbs etc since it consumes less power and offers a more compact product. The heat produced is also less at the same brightness compared to other sources. But unlike traditional bulbs, the LED cannot be simply plugged into a wall socket. It runs on a lower voltage and in order to elongate its life AND do some brightness control etc, we need a circuit which is called an LED drivers. This document is a review of the Infineon LED driver Shield which can be controlled by an arduino and is useful for a lot of projects.

 

 

LED Driver?

Just like a normal diode, we can plot the current and voltage characteristics of LED. I googled it and came up with the following.

 

diode12.gif

http://www.electronics.dit.ie/staff/tscarff/DT089_Physical_Computing_1/LEDS/LED_Characteristics.gif

 

It is easily seen that after a certain voltage, as the voltage is increased, the current increases drastically. Larger current equal to a larger brightness change..This can also cause heat dissipation by

 

P = R x (I^2) = V x I

 

which means I can blow up my LED quite easily. I need a way to control the current through the LED and keep the current at a constant value. So how can I do that? The simplest way I have been making constant current sources has been the LM317 and the circuit looks like...

 

Image.png

 

The 1.25 is due to the internal reference but I wont go into the details because the problem here is that this circuit is based on a linear regulator and is not very efficient nor does it offer digital control.

So how else can I control the current? The simple answer is PWM.

 

PWM Stands for Pulse Width Modulation and simply put, we switch the LED ON and OFF really quickly for a variable duration of time. The longer we switch it on, the longer the current flows and larger the average current and brighter the LED. Take a look at the image below.

 

diode44.gif

(http://www.electronics-tutorials.ws/diode/diode44.gif)

 

So my arduino can do that by default. There are PWM modules in built right? So whats wrong with that? Well you can switch the LED ON and OFF using the Arduino and you could probably do it using say a 555 in an astable mode too. I have used this circuit for some time now where I need variable brightness of the LEDs

Image.png

For a circuit explanation see the video below

 

 

 

The problem with using the 555 is the switching speed. The slower the switching, the more prone to flicker in the LED. The second problem which is common with the arduino switcher is that we have no way of knowing what current is being drawn. Remember we need a constant current and if say one of the LEDs is shorted out, then we have no way of knowing about it and it might even damage the MOSFET. Yikes!

 

The solution is adding a small resistor say 1 Ohm in series with the LED and then use an Op-AMP to monitor the voltage across it. By Ohms law, if there is a drop of 1 volt across the resistor then there must be 1 amp flowing through it! We can read it using an analog pin and then do that for every LED strip and then... aawwwhh. Thats a lot of work!

 

The LED driver shield simplifies this process.

 

What is the XMC1202?

The XMC1202 is an ARM Cortex-M0 based micro-controller which has a dimming control peripheral for LED lighting applications, known as the Brightness and Colour Control Unit (BCCU). It contains 3 independent dimming engines and 9 independent Pulse Density Modulated (PDM) channels. 1 dimming engine and 6 channels are used in this shield.

 

What!?

 

Its an ARM Cortex-M0 core with some dedicate for control of LEDS and ADCs to measure the currents like I said before. The block diagram of the Chips is given below.

Image.png

Whats the BCCU?

Take a look at this...

Image.png

This is a slide from http://www.infineonic.org/download/index.php?act=down&id=4166 and is a presentation on the BCCU itself. The point here is that the ADC needs to sample current at the right time and needs to be fast enough. The XMC1202 can do a lot more as well but for people who just want to control the LEDs using an arduino, Infineon put the chip on a circuit, write a firmware on the processor and made it an I2C slave.

 

If you want to program the XMC1202 there is great tutorial by shabaz sir at

RGB LED Shield from Infineon - Getting Started Guide

 

The RGB LED Shield

 

The RGB shield has the XMC1202 IC as well as the required circuitry to drive LED successfully. The circuit looks like...

 

Image.png

Not much to talk about here. Its the same circuit I have discussed and the DMX section is something not mounted nor reviewed. What we can discuss is that the shield uses only 4 pins from the arduino which are voltage, GND, I2C_SCL and I2C_SDA and I can even drive this using my BusPirate. There is some ready code for the shield and I have attached the example code below.

 

Understanding the commands

The user guide has a long table of commands that can be used to control the shield and the LEDs attached. We will take a look at a subset of the commands and how to use them. In order to send these commands to the shield we can write our own functions but the demo code has ready functions. These are essentially running the I2C peripheral on the Arduino so I will use them directly. There are a number of reasons why I want to do this.

 

Firstly, these are tested functions so it will reduce my prototying time. Secondly, I will probably wrap these functions in other functions which will have a more simplistic interface. In the days of C based network programming, I was taught to write these wrapper functions to reduce complexity but it has a second advantage. If I decide to change my platform to say a Launchpad, then I will write my own I2C driving code in Code Composer and wrap it with the same function as my arduino code. That way I dont need to modify my calling code and the transition becomes simpler. This is standard practice when writing protocols and I picked it up when I wrote my first MODBus Client on an 8051. Now I do this most of the time since I will change the platform at will depending upon the cost of the final product I am building and this means my code is reusable across products.

 

OK Back to the Commands. The first command is intensity which is intensity...

 

Image.png

Simply put, the intensity is a 12 bit value which can be changed by calling ..

 

Image.png

This is simple enough... so what else?

 

 

Peak Current Control.

This is important when you know your LEDs cannot handle more than a specific current. The system is as follows and is explained as well.

 

Image.png

 

This is means I can set the max current by...

Image.png

Another parameter is the Walk Time which is used to smoothly change the colour intensities. The intensities change linearly over time. Take a look.

 

Image.png

 

The last thing I want to highlight is the dimming level. We discussed intensity but...

 

"The dimming engine in the XMC1202 microcontroller on-board the RGB LED Shield performs dimming along a pseudo-exponential curve so that the change appears natural to the human eye. This compensates for the eye’s logarithmic sensitivity to light." ... "The brightness value of a channel and therefore the brightness of the connected LED string, is the product of the intensity of the respective channel and the dimming level divided by 4096.

The dimming engine which controls the dimming level is separate from the BCCU channels. This enables the RGB LED shield to control the colour of the LED strings separately from the lamp brightness. The brightness level of the lamp can stay the same while its colour changes. Changes in brightness do not affect the colour of the lamp either."

 

FROM THE USER MANUAL...

 

Simply put, intensity and dimming are associated with changing the color without changing the brightness of the RGB LED and vice versa. Pretty neat! I encourage you to explore this concept to actually see the effect in practice.

 

There are some commands to read the values as well but I won't need them unless I am facing some color problems.

 

 

Tests

I did some basic tests with the shield but I need to do a lot more to report something. I am using this in my project which will be submitted soon and you can judge if the shield does a good job or not.

 

I will link up more associated posts here as I get them done. For now enjoy the holidays.

 

Cheers,

IP

Previous Posts in the series

 

Prelude

 

Hackers and hobbyists have used the arduino for a diverse number of projects and have made it a very popular. Its simple to use and easy to program. For people who have a slightly 'more' requirement, ARM based single boards came into the market. Initially the ARM boards were tougher to build and program and costlier to make. In order to fully exploit the power of a 32-bit processor, the Linux Kernel was ported to the fanless ARM systems making the Single Board Computers. The OS was stored on either an SD Card or an EEPROM. This new class of boards had the familiar OS system of a regular PC and the digital and analog outputs of the arduino but at a slightly higher cost. Additionally they had varying performance but they started to add something more- peripherals! Keyboard, then Ethernet, then Bluetooth and Wifi- the list goes on. In this article we discuss the Arduino YUN and what exactly it is.

 

 

Single Board Computers Explained

 

Raspberry Pi, BeagleBone Black and the RIOT Board are some of the more popular names. These run Linux or Android and everything runs on top of that. The OS takes care of the memory management as well as peripheral access. The newer kids on the block are the Intel Galileo and the Yun. Thats right! The Arduino Yun runs linux and we will discuss this a little later. For people who want more power and connectivity such as Wifi for IOT applications, we have offerings such as the Texas Instruments CC3200, CC3100 and the CC3000(used in the spark Core). They lack Linux as an OS(CC3200 can have TI RTOS or FREE RTOS though) but have a lot more power than the arduino.

 

Single board computers have come a long way and the linux that runs on them has also shrunk down. Linux tailor-made for a particular Board can go low as 2-10MB in size without support for floating point math. The point it Single board computers make it easy for the IT people and general people to easily get started with a project. The code also becomes a lot more portable because there is an underlying layer of OS which takes care of driving the peripherals like Wi-Fi. This also means that you can start working with languages such as python and do not have to worry about the kernel or C-programming or driving the peripherals. It is simplified into an import statement. On the flip side if you wish to get down into the pits and write your own C-code(or even assembly) you could prefer options such as CC3200 and the like. Its actually not that bad since manufacturers produces a lot of example code and starter projects for these boards. I usually start with the given code and add or delete parts that I need. This increases the prototyping speed as well as the dependability of the code and if you think thats cheating, please feel free to write device drivers for your systems and your own database management systems and let me know

DSC00447.JPG

 

A comparison of the most popular boards is given at https://learn.adafruit.com/embedded-linux-board-comparison/overview and I will do one myself once I get to setting up some tests.

 

Who is the Yun

The word 'YUN' is a Chinese word and means 'Cloud'. That simplifies the purpose of the board right? The Arduino YUN is a modified Arduino with the number of processing elements upped to two. One is the ATmega 32u4 which is directly accessed via USB and the Arduino IDE. The second is the AR9331 which runs linux and can be accessed via the ethernet/Wifi interface or the BRIDGE. The basic block diagram of the system is shown below. The OS is stored on a 16Mb Flash memory and the processor running it is a Atheros AR9331 @400MHz with 64Mb DDR2. Thats pretty good actually.

yun_by_pighixxx-d6qvbq4.png

(Image : http://fc07.deviantart.net/fs71/f/2013/290/a/e/yun_by_pighixxx-d6qvbq4.png))

 

Another thing I want to clarify is that the Arduino Website says that it runs Linino Linux but the banner says OpenWRT. Linino is based off OpenWRT which is a linux distro meant for Embedded devices which are typically wireless routers. Its a completely different animal and is build ground up to be easily modifiable using modules. In short the YUN is a single board computer with a small amount of RAM and Flash which can connect to the Internet and also has an arduino connected on the same board. This gives you two worlds on the same board and if want to build something with the libraries of arduino and have internet applications connected via python or nodejs or the link this is definitely the board for you. If you want something faster and can spend more, the other kid is the Intel Galileo which runs everything on a 32-bit quark processor which runs arduino sketches and everything else on the same core. But thats a different story.

 

 

Getting started with the YUN

 

There are a lot of good tutorials already on the internet and I try to refrain from rebuilding the wheel hence I will link them below. The only thing I want to point out is that the arduino is quite simple to get started with and its not necessary that you go into the nits and grits of the Linux part. Its designed for people who work with the Arduino and want wifi and a few other facilities and do not want to mess with connectors and addons and stuff. Once you are done with the basics, you can start work on python and nodejs and other stuff. But because the RAM and flash is severely limited, you might want to watch your memory usage. Adafruit has a great tutorial on using the YUN as a networked Cam which means that it can take photos from a USB camera(there is USB HOST controller present) and send it over the network. What you do with it depends on your creativity.

 

There is another tutorial on extending your linux space to the SDCARD and you can store a lot of data on the memcard. The link is given below and if I ever get around to that requirement I will make another post and link it here as well. For now I am more interested in seeing how this little peice of tech can be used for IOT Applications.

 

 

Getting a little more started - Enter Temboo

 

The internet of things means connecting devices to the internet and for the beginners this may seem like a daunting task. With the YUN, I recommend visiting temboo.com .  Temboo is a service which generates code for IOT application tasks such as reading twitter, facebook, dropbox and even google services. The generated code can be in your favourite language such as Java, Python or JS and if you go into IOT mode it will generate code for the CC3200 or the YUN! This allows for simplification of some tasks and then you can build your application around it. Temboo has choreos which are essentially steps for performing a task and the system is pretty simple. The basics  are available at

graphic-arduino-howitworks-2.png

 

 

I am still digging at it and my objective is be able to control the YUN using MQTT however I have a Raspberry Pi which is running OpenHAB and an MQTT server hence all messages are to be generate by the PI. No problem since my RPi can run the same Python or NodeJS script as the YUN so I am currently working on formulating a NodeJS/Python script which is a Choreo from Temboo. More on this in the next post since I am still working out some bugs.

 

 

Conclusion

 

The Arduino Yun is easy to use and for those who want to play with IOT and want to be able to use the Arduino IDE, you can use the Arduino Ethernet. For Wifi connectivity there are other options which will be cheaper than the YUN. The YUN is for people who want to start with Single Board Computers, Linux and want to start scripting and move up to more complicated use cases. Arduino cannot do encryption nor the more processor intensive stuff and thats where the YUN steps in. If you want databases and some multimedia stuff, then move upwards to the RPi or the BBB or RIOT but for people working with mid range IOT applications and have the budget for it, the YUN comes highly recommended. Buy one, make a project and see where that goes...

Link to previous post

[Dynamic Living-room Lights] Description

 

Brief

The basic idea is to connect living room lighting to the internet and make them work together with holiday lighting so that the entire system functions as a whole. In this post I discuss the structure of the system.

 

Straight to the system

 

The system is quite simple. I drew up a diagram for the basic functionality which looks like...

iot lights.jpg

 

The center

 

The center piece is the Raspberry Pi which has an existing install of OpenHAB. It also has an MQTT Broker running so that if we loose internet connectivity, the system can still function manually. It has the Infeneon Shield and an LED strip which illuminates the room's back wall. This provides the mood lighting and the software control is explained briefly in the previous post.

 

Submodule 1

 

The Shelf panel is also lit up to create a lighting system that does not need to be taken down after the holidays and is controlled via IR. I bought some ready to install lights but redid the shelves and wall.(Pics coming soon.)

 

 

Submodule 2

 

The Arduino Uno is connected to the Yun via either a cable or a 433MHz RF link. The decision will depend on the distances and locations at the time. I have started work on the tree which is near the back wall and hence for the sake or cost reduction, I might kick out the RF bit to be on the simpler side. The christmas tree has RGB LEDs which can be made to glow in any pattern and are controller by the UNO and the system uses a string of RGB LEDS for this.

14%2B-%2B1

 

Submodule 3

We have a santa doll which is also preprogrammed with jingles. Instead of making my own, I am getting one from the toy store and installing an IR trigger which can be controller via the YUN. The functionality is that everytime someone tweets or emails me seasons greetings, santa will let us know.

 

 

Sound input

I thought about this a lot and came up with a simple solution. I have an FM radio connected to the YUN's input and the frequency is fixed. I hacked an old radio from my junk bucket and it works! Next I made a small FM transmitter which can be tuned to transmit to the rx. Now I have the sound input movable across the room. It can be placed in front of the sound system or on the table.

 

 

Mystery module.

More on this IF the rest gets done in time

 

Progress

 

The tree is a work in progress and I am doing the walls. The place looked pretty dull and is getting a once over. I am waiting for some LED trips to show up and experimenting with the YUN.

 

The openHAB system has been running for sometime and I will integrate with it directly which should be simpler.

Filter Blog

By date: By tag: