GSoC ’13 at BeagleBoard.org

TL;DR  Worked as a GSoC intern at BeagleBoard.org and would love to thank all the people involved.

This years Google Summer of Code has drawn to an end. I worked on the Userspace-Arduino project with Parav Nagarsheth.
I was mentored by David Anders, Andrew Bradford and Matt Porter .

I had some serious fun this summer.

Made a tutorial video, documented a lot about the project on the wiki and wrote a lot of code !

I’d love to thank Dave for all the amazing guidance that he has been giving us throughout the summer. I, and Parav too, started working on the project even before the student list was put up. We were making small changes to the Dave’s Energia fork then. He has been pushing us in the right direction ever since, and I hope that he continues to do so.

mdp(Matt) and bradfa(Andrew) have been helping us out with a lot of things. We’ve had loads of discussions on #userspace-arduino about coding style, do’s and don’ts in our implementation, pros and cons of implementing a certain thing in a certain way

We were able to complete all the core functionality and were able to add support for commonly used libraries.

Because of GSoC, I got introduced to a *very* helpful community. #beagle and especially #beagle-gsoc have been very forthcoming with any and all kinds of help. The weekly meetings were a fun way to hang out with everyone. I learned how to ask questions (still a bit rusty), etiquette’s of IRC, how FOSS projects really work (basically people from anywhere in the world, having fun, coding and helping out each other). I learned how to write wikis. I learned how much more you can learn from actively participating on community forums and groups. In my case this was the G+ Beagleboard.org group.

A bit unrelated, but because of my association with the community and this project,

  • I gave a lightning talk at PyconIndia on using Python with the BBB
  • I conducted a workshop at my local hackerspace on using OpenCV with BBB
  • I am using the Black for my Bachelor’s thesis which is about Cloud Robotics
  • We are building a quadcopter at my local hackerspace using the Black.

Although this formally concludes the Google Summer of Code ’13 part, this is in no way the end. There are a lot more things in the project that have to be done. I’ll be helping to maintain the project along with adding functionality to it.

During the entire summer, I came across a lot many new project ideas. Implementing them during GSoC was not entirely possible because I had to make sure that the promised objectives from my project proposal would be completed. Here’s a list of some associated ideas that I want to work on

  1. Work on making Userspace-Arduino truly generic
    Right now there are some parts in the libraries which are BBB specific. For example, the analogWrite/PWM bit is hard coded for the Black. Get rid of all such bits in the code
  2. Support more boards
    This is basically building up on the above point. Once we have a generic platform, we can easily add more and more boards
  3. Create custom dts
    I had this idea that one should be able to create a custom dts based on the code that has to be compiled. (Assuming that particular function is available in the mux of that pin). Jason Kridner has something similar in BoneScript here. I’d like to create a framework in which we can have a file containing all the possible pin_mux values for each pin for a particular board. Once you give a source file ( in our case a .ino file), it’ll parse the source code and generate a symbol table of sorts with each pin used and the desired pin_mux for it. Based on existing templates, a custom .dts file will be created, compiled and loaded.
  4. ProtocolCape
    Dave had this idea of having a cape on similar lines to the Bacon Board that will make it easier for newbies to get started with all the different interfacing protocols that are available with the Black. So we have I2C, SPI, CAN and Serial on board. A cape which has all the interfaces in a more usable format, with all the right connectors along with software support in the form of the right dts and demo codes.
    Have created a project page here. Hopefully it’ll be easy to get started with an idea like this by looking at the works of Michael Leonard and others who participated in the TI Intern cape design contest.

Open Source and Me hereafter:

Before GSoC I was a very passive user of all things FOSS. I relied heavily on it in my projects, but would never contribute back. That was probably because of lack of confidence and a notion in my head that the guys behind these projects are some kind of Jedi masters who know the secrets of the Force (or in this case Source). All of this has changed for the better now, I guess. I feel less intimidated to meet me people, in real at conferences or in forums,channels, etc online, talk to them and share ideas.
The most important thing that I realized during this time was that it’s not about code. It’s not *just* about code. It’s about having something which people would use willingly. Something they’d love to invest their time in to improve. Something which adds value.
I attend quite a few conferences. But now when I think of a conference, I think how I can talk about some topic there. How it’d be cool present such and such topic there and what all I can include in that.
A lot many people who made it big in the open source world started out with Google Summer of Code. My favorite read was about webchick from Drupal who is a core contributor there now. There are plenty of such examples everywhere.

To conclude,

A well spent summer. A good start to for my FOSS journey.

Advertisements

Week #9 progress with SPI

This week was week number 9

Time’s flying now.
Some minor issues with SPI.
So the BBB has 2 SPIs, ones taken up by the HDMI virtual cape, so no worries there. (Although I’d love to add support such that when the HDMI cape is inhibited, I could use SPI1 as well.  But that’s for laters.
BB-BONE-BACONE dts uses the SPI0 pins for the 7 segment leds.
So basically the pins are in mode 7. But we need them in mode 0 because we’d like to use spidev ( we could of course bit bang using these GPIO pins, and then we won’t need to work around the dtbo issue)

Right now I am using the dts found here, courtesy of Carl Johnson. But that doesn’t have the rest of the bits required by Bacon board, so I am running into all sorts of errors for PWM, etc. ( who expect them to be loaded by default ). This isn’t that big an issue really. We can change the BACONE dts to reflect SPI mux for the requisite pins, but then that’ll break most of the examples because they need the 7 segment.

Apart from this issue, I had a minor issue with #define SPI_CLOCK_DIVx bits. These are basically used to determine the clock speed of SCLK in SPI. Arduino defaults to 4Mhz  which is one quarter of 16Mhz, the system clock freq. Now the dts I am using has a  spi-max-freq of 24000000 (24Mhz). Now I want to make this compatible with Arduino without losing out the advantage of having a higher SPI clock rate than the same.

So #define SPI_CLOCK_DIV4 which means 4Mhz in Arduino, would mean 6Mhz in Beaglebone Black.
So do I want to keep it compatible to the SPI examples already with people, or do I want to utilize the full potential of the Black ?..

That’s one more issue I was facing.

Apart from that I had some minor issues with the SPI ICs I was trying out with my Arduino, but that’s done for now.
Really need to pick up speed now. Quite some ground to clear before September 20th.

Cheers.


Week #8 : Adding non-core libs (SPI) and review of objectives

This week was week #8 at Google Summer of Code.

We’d been planning to do serial for a while, but decided on Wednesday to tackle SPI and I2C first. Serial needs some thinking as we need a way to make things work on all platforms, and we might need serial for that. So that’s on hold for a bit now.
After a very *fair* online lucky draw, courtesy of Andrew, we decided that I’ll be doing SPI and Parav will do the I2C bit.

To get started with, we decided to have a libraries/ folder in our file structure so as to include non-core libraries like I2C, etc. So we had to make the requisite changes in the Userspace.mk file so as to dynamically link those non-core libraries that are included in the code that is being compiled. We already had something like that in our code, which would use some sed magic to get the names of the files that were included in our code and link to them by adding them to ARDUINO_LIBS variable in the makefile. But for some weird reason which I have to debug yet, I haven’t been able to do that. bradfa had the idea that we could include all the libs that are in the libraries folder instead of going through all of this, but for that we decided that I’ll run a few tests that will measure that time and space difference in the build with and without static linking. So that one thing I’ll be doing this week.

SPI is not a tricky bit to be honest. There exists a lot of kernel documentation around that. But the thing is that there are a lot many parameters made available in the structs. So the SPI class constructor will need a lot of defaults to match the defaults set in Arduino. I am referring the online docs at arduino.cc as well as the 1.5 ide branch of Arduino for the same.

I also thought that this would be a good time to reflect on the objectives achieved till now and the ones that are to be delivered by the end of the project. Honestly, there is much to do in this project. We could do so many sample codes, videos, documentation and support more and more boards. But the main objectives that I really want to achieve by the end of September, so that I can say I had a good summer of code are

  1. Have a very good documentation setup.
    Wikis are looking good so far. I need to add details about the functions whose implementations have changed in the wiki. I have already linked the ones that have remained the same to arduino.cc
  2. Complete the core functions We are almost good on this part. I have listed all the core function on the wiki and most of them are green. Some need working, prominently millis/micros and the interrupt functions. I had began working on millis/micros but that turned out slightly more trickier that I thought. Will come back to that later. attachInterrupt, etc have to be tackled as of yet. But apart from these 2-3, we have all other done
  3. Most commonly used libraries
    SPI, I2C, Serial are the prominent ones here. I’d love to get the LCD lib on board too (I happen to use that a lot on my arduino). Will have to talk with the mentors on this one though. They’ll have a better idea of the things which we should focus on
  4. Operating System support
    Linux is easy. Mac and Windows are not that straight forward.
    This bit is tricky. Initially we started working on the Energia IDE. But that got a bit haywire with the number of new repos that we were creating for different parts of the project. So we got it all together and decided to worry about the IDE later. That’s worked out pretty well for us though. Although I’ve mentioned in my proposal that I’d be working on getting all of this to work with the IDE, I am having second thoughts about it now. Never really like the Arduino IDE myself (Emacs user here), but I certainly don’t represent the majority of Arduino users. Having said that, I’d be really glad if we can have a uniform way in which we can have an IDE to write code on the host machine / BBB itself and have the code sent over the black for compilation. That way we  make it easier for a user to start coding ( get rid of the cross compiling bit completely ). Plus we have the stdout which we can send back to the host machine if needed so that we can monitor what’s happening ( while compilation or even after that )
    Is the Energia IDE the best way to do this ? Well that’s a tricky one. But if we can find a better way to do this I’d be more than glad to do it that way.
  5. Videos
    Have a couple of pretty decent videos. My last one was terrible to say the least.

That’s all for this week fellas !

Cheers !


Week #4 More bacon ! PWM and 7 segment this time

Last week was the 4th Week of GSoC ’13 at Beagleboard.org !

Just like the previous week, this week we were working on getting demos working for the Bacon Cape. We now have the PWM, the ADC and the shift register working.
Basically that means that you can display different colors on the RGB LED, use the slider to get analog values and use the 7 segment LED to display your favorite single digit number 🙂 !

I started out with a little clean up of the previous weeks code and then went on to tackle the 7 segment bit. It was fairly easy as prpplague had already got the shift_out in place. Some of the useful bits were found in the Danger cape demo (an Arduino shield similar to the Bacon Cape) from Sparkfun. Apart from that panto has written a neat bash script to test all the features of the Bacon.
Using that script, the next thing I tackled was the PWMs (well I had said that I’d be doing ADC and hatguy would be doing PWM in my previous post, but then later on we traded our to dos). So I added 2 new functions, one the pwm_export function to load the PWM pins from init(). The other one was the analogWrite function in wiring_analog. It was a slight headache to get all the pins right ( the port pins, the pwm_pins, the ones from gpioDescription, the Arduino pins, etc etc).

So now you can try out 2 demos from the examples/ directory to test out stuff
7 segment
PWM

Apart from that hatguy and prpplague got the ADC working. Also, prpplague tested some of our code on the Minnowboard and it worked fine ! So that’s a good indication that our code is generic enough and will support loads of other devices in the future.

This week we will be working on clean up and testing mostly. A lot needs to be straightened out. Some demos work as is for some people while some of the mentors are having trouble getting them to work. So we will be working on getting all the documentation right. mdp and bradfa will be helping us out with this part a lot. Me and Parav are already getting a lot of feedback from all 3 mentors about the stuff that’s already up, and this week we’ll be working on getting some more and straightening out the wiki, etc

All in all, a good week 🙂
Till next time !


Week #2 – Bricked laptop, testing functions and a little local community building

The past week was my second one at GSoC 13.

To be honest, as compared to the first week, this week was slow. I lost the use of laptop, for some hitherto unknown reasons. It was a Dell Vostro 1520, which I was using for almost 4 years now. I still have no clue as to what happened, but I suspect a motherboard failure here (there was no LED activity at all).
So I spent the entire weekend fretting over that.
Luckily I now have access to another machine (a better one when it comes to specs) with almost everything I will be needing. I installed Ubuntu, instead of my usual Debian, to save time in configuring. I figure I have everything that’s needed now ( git repos, tool chains, ssh keys to devices, etc etc)

Before all of these distractions, I was working on setting up the basics for the blink code. Me and Parav have divided the work amongst ourselves for the blink part. I would be taking care of all the functions that will be required for accessing /sys/ as well as stuff like delay, etc. Also, communication over ssh is something else that I am taking care of.
Parav is working on the pin_mux as well as the Makefile. The makfile part is pretty cool. The aim is to enable anyone to just download the libraries and makefile and let them write code using the arduino like functions in their own IDE ( Emacs, Vim, etc). So basically this is for folks who are not exactly newb to programming in general, but are new to Embedded Linux and the BBB.

The testing part which I mentioned in my last post was good. I found out a few minor errors I’d done in my previous code ( value to be passed to the functions should be a char[] instead of int, among other things). Also, I pushed it here. If anyone would like to test the code, you can just clone the repo, setup ssh keys for your BBB using the instructions in the bash file. And run it as ./send_exec generic_function.c
The code will compile, upload and execute. Right now I have enough functionality to turn on/off a usr_led, export/unexport a gpio pin and set/get its value, direction, etc.
So the next thing I will be working on is the delay function which will allow me to blink a LED. I hope to get this up and running by Wednesday (for the weekly meeting).  Once we have the core functionality up, we can tackle bigger things like pwm, adc, etc.

There exists an Internet of Things meetup in my city (Pune, IN), where Arduino hackers meet to work on awesome projects.
BLOG GitHub
Most of the projects that are done here using the Arduino. But we also have a few Raspberry Pi enthusiasts amongst us.
So this week I gave a small demo of the BeagleBone Black (since I got it last week) and we had a nice discussion about the features of the Black, and the differences between the Arduino, Pi and the Black. I also talked about the userspace-arduino project and how we can use the same IDE and the same code/libraries for programming on the Black.
Some photos

Till next week !


Userspace libraries for the BeagleBone Black

The number of ARM Linux boards is staggering. So is the number of people who are new to them. Actually the whole maker movement is gaining a lot of traction.
Most people start out with the Arduino, because of its simplicity, price, excellent documentation on the site as well as the quantity and quality of projects that have been done using the same. So all in all, the Arduino is the newbies de facto entry point.
A lot many projects have been started to make it easier to start embedded Linux development. Ours is a similar effort.

The project proposes to build a set of Arduino-like libraries for development on the BeagleBone Black. The libraries will be available inside of the familiar Arduino IDE( to be particular in the Energia IDE) . Also, we intend to work on various communication interfaces which will allows us to upload, execute and fetch the results of the code.
Look here for more details on that http://www.elinux.org/Userpace_Arduino

The major objectives that we have in mind are:

  • Get the code for GPIO, I2C, PWM, SPI, ADC and Serial to work on the BeagleBone Black, as is. For example, it means a analogRead on a compatible pin on the BBB should work just like it would on the Arduino
  • Ensure multiple methods of communication between the IDE and the board
  • Ensure that enough documentation is there for someone to get started. It would mean creating or making things compatible to existing wikis.

Parav Nagarsheth and I will be working under David Anders as well as Andrew Bradford and Matt Porter.
All of us can be found at #userspace-arduino on Freenode.

Follow us on GitHub
Project blog

I’ll be uploading a video with our objectives in detail soon enough.
Cheers till then !


HOWTO make a binary clock using Arduino

This is a tutorial on how to make a binary clock using  Arduino .

What you’ll need :

  • 10 LEDs + 220 ohm resistors
  • Arduino Uno (Thats what i used , but any would do)
  • Wires
  • Breadboard

I’ll be showing how to  make a binary clock with hours and minutes , but if you understand the code and have enough pins on your boar you can easily modify the code for including seconds .

If you are using the Uno , then its kinda tough to fit in seconds because that will require 16 digital pins . You could manage it with the analog ones though .

If you see how binary numbers proceed , then you’ll notice that the state of the left-most bit i.e. the LSB changes for every change in state of the number as a whole .The 2nd bit from the left changes after every 2 changes of state , 3rd after every 4 etc . So if a number MOD 4 = 0 , then the state of the 3rd bit toggles .

Example :: 5 is 101 in binary .

next state is 6 . Now , 6 MOD 1 = 0 , so 1st bit will toggle .

6 MOD 2 =0 , so 2nd bit will toggle .

6 MOD 4 is not equal to 0 , hence value of 3rd bit doesn’t change .

so , 6 -> 110 in binary .

This is the logic that I have used .

int state_1=1 ,state_2=1 ,state_4=1 ,state_8=1 ,state_16=1,state_32=1 ;
int count=0 ;
int hour1=0 , hour2=0 ,hour3=0 , hour4=0 ;
int count2=0 ;
void setup()
{
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);

} ;
void loop()
{
if(count == 60 )
{
count = 0 ;
count2++;
if (count2==13)
{
count2=1 ;
}
//hour1
if (hour1==1)
{
hour1=0 ;
digitalWrite(7,LOW);
}
else
{
hour1=1 ;
digitalWrite(7,HIGH);
}
//hour2
if (count2%2==0)
{
if (hour2==1)
{
hour2=0 ;
digitalWrite(8,LOW);
}
else
{
hour2=1 ;
digitalWrite(8,HIGH);
}
}
//hour3
if (count2%4==0)
{
if (hour3==1)
{
hour3=0 ;
digitalWrite(9,LOW);
}
else
{
hour3=1 ;
digitalWrite(9,HIGH);
}
}

if (count2%8==0)
{
if (hour4==1)
{
hour4=0 ;
digitalWrite(10,LOW);
}
else
{
hour4=1 ;
digitalWrite(10,HIGH);
}
}
state_1=1 ;state_2=1 ;state_4=1 ;state_8=1 ;state_16=1;state_32=1;
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
}

//minutes

//toggle state_1
if (state_1==1)
{
state_1=0 ;
digitalWrite(1,LOW);
}
else
{
state_1=1 ;
digitalWrite(1,HIGH);
}

//toggle state_2
if (count%2==0)
{
if (state_2==1)
{
state_2=0 ;
digitalWrite(2,LOW);
}
else
{
state_2=1 ;
digitalWrite(2,HIGH);
}
}
//toggle state_4
if (count%4==0)
{
if (state_4==1)
{
state_4=0 ;
digitalWrite(3,LOW);
}
else
{
state_4=1 ;
digitalWrite(3,HIGH);
}
}
//toggle state_8
if (count%8==0)
{
if (state_8==1)
{
state_8=0 ;
digitalWrite(4,LOW);
}
else
{
state_8=1 ;
digitalWrite(4,HIGH);
}
}

//toggle state_16
if (count%16==0)
{
if (state_16==1)
{
state_16=0 ;
digitalWrite(5,LOW);
}
else
{
state_16=1 ;
digitalWrite(5,HIGH);
}
}

//toggle state_32
if (count%32==0)
{
if (state_32==1)
{
state_32=0 ;
digitalWrite(6,LOW);
}
else
{
state_32=1 ;
digitalWrite(6,HIGH);
}
}

delay(60000);
count++ ;
}

Minute bits have value till 59(111011) . So , we will require 6 LEDs to show the minutes . And I have considered the 12-hour format , so that means I’ll need 4 LEDs for hours . A 24-hour format will require 5 LEDs .

Here are 2 images showing the time as 12:11 and 12:53 !

Cheers !