SmexyyWeby

Scripting for Fun and Passion

Intel Galileo Gen 2 Board for interfacing internet of things: Controlling LED Via Web


If you are following this blog series, I hope you are comfortable with running a big Linux image on your Galileo as explained in my previous post.

In this post we will be using the Intel Galileo board to run a web server which will serve a page for controlling an LED connected to a board. This means that if your board is on a network any user can access the page served by the board and switch the LED on or off. The implications and extensions of this example app can be for controlling any device connected to the board via the web.

In this post we will work using a different linux image called the Internet of Things version. This image comes with many plugins for interfacing the with the GPIO pins and running web servers. You can download this new image from the Intel IoT downloads page. More details on  this image and its usage can be found at the intel pages. Also, I would like to point out that the steps for installing this image on the SD card are quite straightforward but also different from installing the default image I mentioned in my older article and require downloading of additional software. You can find detailed instructions for installing this image for windows platform on the intel page.

Once the image is installed you can connect your device to your router and have it available on your network. Now you can run a web server directly on the image using python or the LightHTTP package which comes with it. However, the Inter IoT community has released an XDK which I will be using in this post to configure the web server and send signals to my GPIO pins to switch the LED on/off. The XDK is for running Node.js code on the board and comes with sample code for interfacing with the pins.

The XDK will detect the board if it is present on the network and will deploy the code. It has easy options for starting the deployed app and stopping it all without physically connecting to the Galileo. The editing experience on it is a bit clunky but it serves the purpose of file deployment. I edited my main code in another editor and used the XDK only for deployment.

I used the IoT local temperature example as a template and modified its code to configure the Node.js server and the board interaction.

The app requires 3 important components and all the code is available at: https://github.com/napsternxg/IntelGalileoIoT_LEDOnOff

  1. LED circuit connected to Galileo
  2. Web page with On/Off switch served by the Galileo
  3. Sending the input from web page to the pins.

The final product looks like the following images (click image for more pics):

LED circuit with Intel Galileo

LED circuit with Intel Galileo

 

In my web app I have used the Socket.io plugin for sending and receiving the signals asynchronously. The main component of the code for interfacing with the GPIO pins is the one using mraa plugin.

var mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console
var myOnboardLed = new mraa.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
myOnboardLed.dir(mraa.DIR_OUT); //set the gpio direction to output
var ledState = false; //Boolean to hold the state of Led

After initializing the pins we just need to use the following piece of code to switch the LED on/off.

myOnboardLed.write(1); //Send High leading to LED ON
myOnboardLed.write(0); //Send Low leading to LED OFF
LED On Off Web Interface

LED On Off Web Interface

Overall this was a major step for me in understanding the concept of internet of things and getting my first internet of thing (simple LED) to be controlled over the internet at the flick of a button.

Calculating Pi using Monte Carlo Simulation


Recently I have been intrigued by the uses of Monte Carlo simulation and a myriad of their uses in probabilistic modelling techniques especially in NLP and social network modelling. I wanted to learn more about the monte carlo process and understand what are some of its basic uses. An often cited example people gave me was that of calculating the value of $\pi$ defining it as 4 times the area of a circle inscribed in a unit length square.

The below figure shows the distribution of randomly generated points falling inside and outside the circle. Also the other figure shows how with the greater number of iterations the value of pi converges to the actual value of pi.

Monte Carlo Method for approximating the value of pi using ratio of area of circle inscribed in unit length square.

Monte Carlo Method for approximating the value of pi using ratio of area of circle inscribed in unit length square.

The intuition behind the simulation process is that if we randomly generate points confined inside a square circumscribing a circle then the probability of the points falling inside the circle will be directly proportional to the area of the circle. Since the circle is inscribed in the square hence its radius is 0.5 and hence the area will be $\pi/4$. This ratio is also approximately equal to the number points randomly generated inside the square which fall inside the circle to the total generated points. The approximation will should converge to the value equal to pi if we have very large number of points ideally tending to infinite points inside the square.

The below code does the simulation and generates the above figures:

The intriguing thing about this simulation is that using just 10000 points I am getting pretty good value of pi around 3.1392. This approximation however will change with each different run of the code as the randomly generated points change.

I am interested in learning more about such basic applications of monte carlo processes so that the understanding of the more complicated models is easier.

Intel Galileo Gen 2 Board for interfacing internet of things: Getting Started


This semester I have signed up for the course INFO 490: DIY with Galileo Development Boards which is a DIY fun course on trying to use the latest Intel Galileo Gen 2 board for variety of playful and useful purposes. I will be trying to document this course in the series of blog posts starting with this post about getting started with the board.

Introduction to Intel Galileo Gen 2:

The intel galileo gen 2 board is a step ahead of the regular embedded systems development boards like Arduino and Raspberry pi in the sense that that is has the full capabilities of Arduino as well as the Intel Quark processor with 256 MB DDR3 RAM. The board thus allows the capabilities of controlling embedded circuits as one would do with an Arduino along with running a linux image which can also be used for controlling the Arduino style GPIO pins on the board. There are tons of resources both on the Galileo website as well as some good tutorials on Sparkfun on how to connect the board and use a demo sketch to use the Arduino side of things as well as details about running a large Linux image on it to do complicated stuff like connecting to the internet. The following are some resources which one can use to get their Galileo board up and running:

Using Bigger Linux image via SSH over ethernet:

This is an important and useful thing to learn and configure on the board. If you plan on using more than the Arduino interface and try the Linux interface of the board you will get a lot more flexibility. There are 2 ways to use the console of the board. One is using the Serial port to access the console and another is using SSH connection over ethernet port to the bigger Linux image. Below I will try to explain in detail how to use the SSH over ethernet port which is a much smoother way and can also be use over the network. The usage of serial port can be found on the Sparkfun Getting Started page.

In order to get the SSH connection working you will need the following:

  • Ethernet Cable
  • Arduino IDE for Galileo configured using any of the getting started
  • An SD card with at-least 1-2GB memory with the Bigger Linux Image downloaded from the Intel Download page

Now start the board with the Linux Image on the SD card loaded and upload the first of the following sketches [SSH_IP.ino] to the board:

This code will configure the IP address of the board as 169.254.0.2 and you should also set the Ethernet IP of your own computer to 169.254.0.1 and use the subnet mask as 255.255.0.0 for both the systems. The code also starts the SSH service on the board which will allow it to accept SSH connections.

Using the second code above [SSH_IP_LISTEN.ino] one can track what is the current IP of the board. This will be useful for the case when you have the IP of the board configured over a DHCP (usually when you connect it to your home router).

A good way to configure the board would be for it to use a static IP when connected to the computer over ethernet and to use DHCP when connected to the router.

For this to work when you SSH into the board using ssh pi@169.254.0.2 you can edit the following file /etc/network/interfaces to the contents of the file 3 [interfaces] shown above. After this you might loose your current SSH connection. Just press the reboot button on the board and wait for it to load again. Once the board has booted up you can either load the 2nd sketch [SSH_IP_LISTEN.ino] and open the Serial Monitor to see the IP of the board and connect to that IP (this IP will usually be different from the static IP you have set up earlier) via SSH. You can also find the IP of your board by logging into your router admin account and checking the IP of the device which is named after the board (default: clanton).

Once you have the SSH running you can try using the various options you get for controlling the board using the command line. I will try to add more info on playing around with the board via linux in future posts.

2014 in review


The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 39,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 14 sold-out performances for that many people to see it.

Click here to see the complete report.

A review of research ethics of internet using the Facebook Cornell Collaboration


As a part of my course on Social Visualization (CS 467) I had the opportunity to review the following three articles about ethical research on the internet related to the Facebook Cornell study of emotion on Facebook newsfeed:

Here is my review based on the above articles on the issue of ethics in academic – industry collaboration for social research:


Summary of Articles

The different articles all discuss about ethics of research without consent in the social media platforms specifically in context of the controversial Facebook study on contagion of emotions on Facebook. The three articles shed light on the situation from different perspectives. The guardian article discusses the whole situation in detail and talks about the negligence of IRB by all the parties involved in the study i.e. Facebook, Cornell University, PNAS journal. The WordPress article talks about another social scientist’s experience and pros of doing online research without human consent. The medium article talks from industry’s perspective of why these kind of researches continue to happen at industry level and this collaboration with academia just exposes the need to altering the policies for IRB for online research.

Key ethical points

I think the guardian article highlights how all the involved parties have tried to escape giving explanation of the whole situation and questions if the research was funded by the Army. It exposes the details in the facebook data policy which allows the company to run such experiments however the involvement of academic scientists without proper IRB is questionable. The article also discusses on of those scary situations where the nexus between corporate and academia will be looked as a way to bypass ethical research standards, which is not a good thing.

The wordpress article is by another social scientists who explains using her own previous researches that if the research doesn’t cause any harm then it should be allowed. She offers suggestions on making the research non-harmful by removing the negative sentiment aspect from the study. In her previous research the author entered various chat forums and depending on the experimental design shared their intention of doing research and allowed system to kick them out if the chat room was unwilling to participate.

The medium article talks from the perspective of a previous data scientist and current academic researcher. He advocates the need for a differentiating social media IRB policies with that of the real world scenario. Socio technical systems allow us to run very huge sized experiments with high efficiency which is not possible in the physical world experimental setting. He also details how making online research systems include a consent form and other nitty gritties of IRB requirements makes the systems unusable and reduces the participation because of people’s fear of things that can happen to their data.

Conclusion

According to me, the industry and academia collaboration are really useful and required if we want to do representative researches. Most of the research which happens by the academic community is on very small sample of social media data because of their lack of access. The corporate partnership if done for a more academic cause would help in getting more useful results which can be applied back to the advancement of social systems.

Also, any kind of research which may cause any kind of physical or mental pain should be highly regulated. This however, gives an opportunity to tackle this problem from a more user interface perspective as well. How can we make interfaces which don’t scare people away from participating in research and how can they still serve as mediums of communication of the way the user data will be used.

We cannot control what experiments which corporate companies run without our consent and we rarely get to even get access to their results. Most of the experimental results are used as cash generators for future. However, with the corporate and academic partnership these results can be used for not just the revenue increase of the company but also to advance human science and this in a way demonstrates the involvement of the company in question in corporate social responsibility in some way.

To conclude, I agree to the research nexus between facebook and cornell however I feel the effect of the research should have been limited to positive and neutral messages only so as not to cause any harm. To quote the wordpress article “spreading sunshine” in not unethical.

%d bloggers like this: