Sunday, June 15, 2014

The CC3000 Wifi - Part I

I have been messing around with the CC3000 Wifi based breakout board and shield from Adafruit lately and have found a bunch of problems with that CC3000 from Texas Instruments. With a little research over the internet i found that i was not the only one with these problems and many people were facing similar problems with the TI wifi module. To keep things brief here are my findings on the CC3000.

Devices Used - Arduino UNO, Arduino Mega 2560, CC3000 Breakout, CC3000 Shield.
CC3000 Firmware - v1.24
Problems - Unknown hang-ups, Buffer Full.

1. CC3000 WiFi shield + Arduino
I implemented a small weather station a few days ago, details of which can be found here. This arduino sketch runs flawlessly on an Arduino Uno for hours and days without any hang-ups or inconsistencies in behavior. Very strange it might seem, perhaps it's got something to do with the 40 second delay created due to the use of println() function that sends data character by character giving enough time for the buffers in the CC3000 firmare to freeup...maybe...

2. CC3000 Breakout + Arduino Mega 2560
A similar approach to [1] above only that i send a single random number to the Xively site. On the Mega 2560, using the println() the CC3000 used to hand up frequently after 3 - 4 minutes of sending data. Then i switched to the fastrprintln() API where the hang-ups happened after quiet some time usually 20 - 30 minutes. There are two hang-ups that i have observed. One is in the HostFlowControlConsumeBuff returning an error of -3, i.e a timeout as there are no free buffers available on the CC3000. The other is an unknown hang-up that i have not been able to figure out, but i have a hunch that it is in the while(1) of the hci_event_handler function. #defining SEND_NON_BLOCKING has no effect, just making things worse, making HostFlowControlConsumeBuff return -2 frequently. 



The watchdog cannot be used on the MEGA 2560, since the WDTON fuse is set to 1 (unprogrammed). Even enabling and using it results in a continuous resets. I used the method shown below to take care of HostFlowControlConsumeBuff problems in simple_link_send. The SysReset is nothing but this - void (*SysReset)() = NULL. The unknown hangup remains unknown.


I had to modify the Adafruit CC3000 library and added an API for fastrprintln() that took a String object as an argument. 


The firmware of the CC3000 seems to be pretty buggy at the moment. So beware before you buy any product that uses this one. I will be updating soon some crude workarounds and stuff with the Teensy soon using the CC3000...

Update June 19th 2014 

To use the existing fastrprintln without having to add a new member function to the client class we can invoke it as follows

client.fastrprintln(data.c_str())

Where data is a String object and c_str() is the member function that returns the character buffer.
 
I came across this thread on the Texas Instruments community forum. Looking at this there seems to be no hope of getting the CC3000 to work properly. The last time the thread was active was on Feb 2014, since then, complete silence. Looks like the CC3000 firmware team at TI is either working hard or hardly working at all...and right now after almost 4 months i'd go with the latter...


Monday, June 9, 2014

Arduino + Internet of Things - Part I

...IoT...

The term "Internet of Things" is used to describe a system where the Internet is connected to the physical world via ubiquitous sensors [1]. In an article dated June 22, 2009 in the RFID Journal Kevin Ashton said - 

Today computers—and, therefore, the Internet—are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings—by typing, pressing a record button, taking a digital picture or scanning a bar code. Conventional diagrams of the Internet include servers and routers and so on, but they leave out the most numerous and important routers of all: people. The problem is, people have limited time, attention and accuracy—all of which means they are not very good at capturing data about things in the real world.

And that's a big deal. We're physical, and so is our environment. Our economy, society and survival aren't based on ideas or information—they're based on things. You can't eat bits, burn them to stay warm or put them in your gas tank. Ideas and information are important, but things matter much more. Yet today's information technology is so dependent on data originated by people that our computers know more about ideas than things.

We need to empower computers with their own means of gathering information, so they can see, hear and smell the world for themselves, in all its random glory. RFID and sensor technology enable computers to observe, identify and understand the world—without the limitations of human-entered data.


Gartner Inc. states that the Internet of Things will grow to 26 billion units installed in 2020, representing an almost 30-fold increase from 2009. Furthermore, Gartner said that IoT product and service suppliers will generate incremental revenue exceeding $300 billion, mostly in services, in 2020. The market research firm further states IoT will result in $1.9 trillion in global economic value-add through sales into diverse end markets.Is IoT the latest hype ? Most of the opportunities predicted from IoT are nothing new. Everything will be connected but most those items like cars, appliances, printers, etc. have been talked about for more than a decade. The big differentiator this time is advanced sensor technology, but how long before these sensors become commodities? OK, so most of these devices will be IPv6, but what's the big deal about what standards they use to communicate? Most of the chatter about IoT seems to be evolutionary, not revolutionary. [2]

Data is all around us, data we cannot see - Dark Data. If harnessed properly this data can be quantified and utilized to make this planet a better place to live (jeezz...). Unless people make smart use of IoT it will just remain in the evolutionary stage.  Everthing will just remain an Internet-of-Thermostats...

Allright, i am fed up gathering data visit this link to read further.

That Temperature Thing...

Now to the real content for which this post is meant for. In a nutshell - i've used the Sparkfun Weather shield connected to the Arduino to send the temperature, humidity and luminosity data of my room to a Xively server using a Adafruit CC3000 TI WiFi sheld. This is the stacked up assembly. The bottom board is an Arduino Uno R3, in the center there is the Adafruit  WiFi shield and the Sparkfun weather shield on top. Pretty neat arrangement eh ? Rapid prototyping at it's finest with such boards available...


The data is displayed on the Xively website. Surprisingly i have observed that the data transmission to the server is slow. It takes approximately 40 seconds after a connection has been established with the server to upload the JSON formatted data using the UNO R3. The entire code for the Arduino sketch is shown below and some screenshots from the Xively site. Most of the code has been adapted from Adafruit's learning site with minor modifications by me for the weather shield. Does a demo like this come under the hood of IoT ? Well, right now, if i stop this project here, then No, it does not. The data is merely being displayed, it does not control any-thing or talks to any other thing to modify that thing's behavior. This just validates the platform on which future IoT applications aspire to run on...


The light levels started to increase from 05:53 hrs in the morning as seen in above graph.
The sunrise time as per local weather station data was indeed 05:53 A.M

It is pretty hot out here. Those spikes you see are me turning off the air cooling of my room. 37.99 degrees celcius was the maximum temperature hit inside my room...after which i turned on the air conditioning

If you are reading this post and have some information to share on the CC3000 as to why it takes so much time to push data to the website, leave a comment below. Thanks for reading through...





And that's a big deal. We're physical, and so is our environment. Our economy, society and survival aren't based on ideas or information—they're based on things. You can't eat bits, burn them to stay warm or put them in your gas tank. Ideas and information are important, but things matter much more. Yet today's information technology is so dependent on data originated by people that our computers know more about ideas than things. - See more at: http://www.rfidjournal.com/articles/view?4986#sthash.uvAv1voe.dpuf
Today computers—and, therefore, the Internet—are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings—by typing, pressing a record button, taking a digital picture or scanning a bar code. Conventional diagrams of the Internet include servers and routers and so on, but they leave out the most numerous and important routers of all: people. The problem is, people have limited time, attention and accuracy—all of which means they are not very good at capturing data about things in the real world. - See more at: http://www.rfidjournal.com/articles/view?4986#sthash.uvAv1voe.dpuf
Today computers—and, therefore, the Internet—are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings—by typing, pressing a record button, taking a digital picture or scanning a bar code. Conventional diagrams of the Internet include servers and routers and so on, but they leave out the most numerous and important routers of all: people. The problem is, people have limited time, attention and accuracy—all of which means they are not very good at capturing data about things in the real world. - See more at: http://www.rfidjournal.com/articles/view?4986#sthash.uvAv1voe.dpuf
Today computers—and, therefore, the Internet—are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings—by typing, pressing a record button, taking a digital picture or scanning a bar code. Conventional diagrams of the Internet include servers and routers and so on, but they leave out the most numerous and important routers of all: people. The problem is, people have limited time, attention and accuracy—all of which means they are not very good at capturing data about things in the real world. - See more at: http://www.rfidjournal.com/articles/view?4986#sthash.uvAv1voe.dpuf
Today computers—and, therefore, the Internet—are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings—by typing, pressing a record button, taking a digital picture or scanning a bar code. Conventional diagrams of the Internet include servers and routers and so on, but they leave out the most numerous and important routers of all: people. The problem is, people have limited time, attention and accuracy—all of which means they are not very good at capturing data about things in the real world. - See more at: http://www.rfidjournal.com/articles/view?4986#sthash.uvAv1voe.dpuf

Sunday, June 8, 2014

Teensy 3.1 & The RESET Pin


The Teensy 3.1 unlike the Teensy 3.0 does not have a RESET pin to which you can connect a header and access it easily. The 3.1 has the RESET pin at the bottom of the board connected to a very tiny circular pad - the reason being, as Paul Stroffregen says, is to keep the board in a small form factor. For breadboarded projects it is kinda impossible to tap into this pin and have reset functionality available. The only source of a reset is to power off and power on the device. Another method is to connect a wire to the reset pad and if you succeed you get the reset functionality. I however do not like wires dangling about and creating a mess on my breadboarded / PCB projects, also they have a higher chance of breaking off. In this post i describe how i dealt with this situation of accessing the reset pin...
  
Here is the Teensy 3.1 boad with it's RESET pin marked as R on the bottom of the device. 



Take a female header pin connector - the kind of connectors you find on Arduino / shields. You can either get a single female header or break one off a 8-pin header like i did to mine.



Place the header on the board and fold it's pin such that it forms into a shape shown below. Try to make sure that you fold it enough such that the lower curved end and the plastic section of the header are in a straight line otherwise you will find that when the header is placed flat on the board it will start to rock on one side...



Clip off the remaining end of the connector after aligning properly with the board. I placed the header near the board edge right below the USB connector.



Time to solder the header. Place the header on the board and use some tape to fasten it when you solder, thereby preventing it from moving around and getting a dry / nasty solder joint. Try to keep the tip of the header near the center of the pad.


This is what it looks after soldering. The header lies flat on the PCB and the joint is far from breaking off.



The female header is the same size as the male header pins. It can therefore be easily used with a breadboard.



That's it, now you've got a access to the RESET pin in a more respectable manner :P. However, the disadvantage of this approach is that you lose access to the +D pad and cannot connect the capacitor for USB host mode. I never intend to use those, hence no regrets. Make sure to glue the header to the board with some strong adhesive.

Got a better way ? Post it in the comments below and let me know. 

Thanks for reading through....