Wednesday, February 29, 2012

How to convert string to integer in Arduino?

Today just found myself having to convert a string to an integer in an Arduino. Had a code that did character to integer but not from string. So copy from here to there ended up with this function. And posted here just for anybody to use or have a starting point.
Here is the code, use it change it or don't use it. Hope this saves you some time.
 int8_t satoi( char *str, int len ){  
  int8_t r = 0;  
  for(int i=0; i<len; i++){  
   //Check if this is a number  
   if ( str[i] < 0x3a && str[i] > 0x2f){  
     // is a ASCII number, return it  
     r = r * 10;  
   r += (str[i]-0x30);  
   }else{  
    i = len; //exit!  
    r = -1;  
    break;  
   }    
  }  
  return r;   
 }  
 int8_t satoi( char *str ){  
  int8_t r = 0;  
  int len = strlen(str);  
  for(int i=0; i<len; i++){  
   //Check if this is a number  
   if ( str[i] < 0x3a && str[i] > 0x2f){  
     // is a ASCII number, return it  
     r = r * 10;  
   r += (str[i]-0x30);  
   }else{  
    i = len; //exit!  
    r = -1;  
    break;  
   }    
  }  
  return r;   
 }  

Tuesday, February 28, 2012

Progress on arduino tv remote

Today received the zener diodes needed for a virtual usb keyboard and lucky me it worked. I was able to load the virtual usb keyboard libs from the web and run a hello world.
Next step is to put it all together with the irda and ethernet code. I will continue on this tomorrow and hope to complete soon. After this would be a very nice post to share.
Building, programming and sharing would make me go full circle.


Sunday, February 26, 2012

Arming my arduino

Just a view of how looks like an Arduino with a cheap Ethernet module and an infrared led with corresponding receiver. Separated all is working. Is a matter of creating interrupts for multitasking.  If not possible then this could become a dual core arduino project. Oh and this build is missing more LEDs and an USB cable to emulate a keyboard. Oh and of course a mobile phone app.
I just want to complete this project to start using it. And write a post here about it.

Update:
Due to interrupts and clock limitation (also I tried and tried but could not make the two codes into one), the project ended up using two arduino chips. Each connected via serial. One emulating the USB Keyboard and one with the ethernet and IRDA. All this might be able to be resumed into just one arduino UNO board with a different firmware for the usb to serial chip and might look actually better and smaller.



Wednesday, January 25, 2012

Black Widow Arduino first take

A few months ago a friend and I ordered a pair of Arduino Black Widow 1.0 (an Arduino with Wifi). So after a very long time, today decided to plug it in. After searching on the web how to, and literally because I had no idea what to do.
First downloaded the Arduino IDE on Ubuntu and installed (that was easy). But after I had no idea where to start looking.  Googleing and a few Arduino wikis and got exactly what I needed. Some web server and libraries. Downloaded and BAZINGA! it is on the wifi.


If you have to do and you are a "newbee" like me:
1. Download Arduino IDE (my case ubuntu, from the software center like any other program).
2. The black widow is an "Atmel ATmega328P" so I selected from the IDE on Tools->Board->Arduino Duamilanove or Nano/Atmega328
3. Downloaded the Wishield library from the github repo https://github.com/asynclabs/WiShield
4. You may download as a zip file if you like. In that file there is a folder for examoples that you can download where ever, and the code .c,.h files freely I copied them into /usr/share/arduino/libraries/WiShield (Wishield had to be created by me) with "sudo mkdir /usr/share/arduino/libraries/WiShield" and copied the files files that were not in a directory from the Wishield repo into that new folder.
5. Restarted the Arduino IDE.
6. Opened the Web Server project, click on the play button, no errors so clicked on the upload button and waited.
7. Configure your WIFI password and the IP

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,10,5}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,10,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"MYSSID"}; // max 32 bytes
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"WAPPassword"};


8. It downloaded to the Arduino (ok you must had plugged the Arduino to your USB) so it took a little time (less that 30 seconds) and the blue led came steady ON indicating that it was on the network.
9. Went into my web browser typed in the manually assigned IP address of the arduino and that's it. It is online!

So now you and I officially deployed an app to the Arduino, let's see what else (some other day).
Oh by the way, my girlfriend said "What is that", and I like a good nerd "Oh this is an Arduino, a micro-controller that can be used for a lot of cool things...". Sadly she cut me short just by saying "Ok, I really don't care". So sad right! We nerds that is our cross.



Tuesday, January 10, 2012

Repo Sync of cyanogenmod 9

After long time with problems downloading the CM9 source code for Ice Cream Sandwich. Apparently is downloading now.
The error message that haunted me was:


Fetching projects:  95% (232/244)  From https://github.com/CyanogenMod/android_prebuilt
 * [new branch]      gingerbread -> github/gingerbread
 * [new branch]      gingerbread-release -> github/gingerbread-release
 * [new branch]      ics        -> github/ics
Fetching projects:  99% (242/244)  error: Cannot fetch CyanogenMod/android_frameworks_ex

In order to solve this from a forum (http://forum.cyanogenmod.com/topic/39528-cant-dl-source/) had the link for the correction in the manifest.

To fix I did this:
1. Replace the default.xml manifest file from SOURCEDir/.repo/manifest/default.xml with the one from http://r.cyanogenmod.com/#patch,sidebyside,11353,1,default.xml . (please use the new one)
2. In my case since the problem was with one specific project, I did removed completely the folder SOURCEDir/.repo/projects/framework/ex completely.
3. repo sync  (this fixed all and recreated the project ex with the correct stuff)

Now the actual compiling is the challenge, but fun to do. Programming = 0, just copy paste and commenting stuff. Maybe eventually something will come out. But every build takes a lot of time just to know that I'm still missing something.


Thursday, December 29, 2011

Place PDF from Google Docs into your Blog

Posted a how to post a Presentation from Google docs into your blog. Presented my findings to my friend and it got back again to me. "No is not a presentation but a pdf that I want to show" - he said. So lets start all over again but now with a pdf.
The PDF embed into this post has the details on how to, however I will quick break down the steps.

Will try to show in a few quick steps on how to

  1. We assume you have a pdf file already.
  2. Upload your pdf to your Google Docs account.
  3. Share your pdf and set it to be public.
  4. Copy the link given from Google Docs of your pdf
  5. Paste the link into the address bar of your browser
  6. Copy again the resulting link from the address bar of your browser
  7. On the address replace chrome=true to chrome=false and append to the end of the link "&amp;embedded=true" (without the " )
  8. Place your resulting URL into this block
    1. <iframe height="780" src="MY_ADDRESS" style="border: none;" width="600"></iframe>
  9. Change width and height as needed.

Sample resulting block of code

<iframe height="780" src="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=false&amp;srcid=0B10UfrjZDyv1YzNiZDgzZTgtMWM2Mi00YmM4LTg3OGEtZWY3YjQ1NmExMGQz&amp;hl=en_US&amp;embedded=true" style="border: none;" width="600"></iframe>

Embedded PDF in action!





Hope this was useful to you!

Wednesday, December 28, 2011

How to link a Google doc presentation into your blog

Some time ago a friend asked me on how to share a document made in Google Docs from his blog. Well I said I don't know. But as the nerd that I am, could not stop me from finding out.

So here it goes in 5 steps.
1. Create the document (this you may already conquer!!, one down and four to go). Sample is a presentation.
2. Change the privacy settings of your document to make it "Anyone with the link"
3. Go into the right corner to Share - Publish/embed
4. Click on Publish Presentation
5. Copy and paste the code into your blog.

If the instructions are too hard for you, take a look at the presentation bellow.





That is all, hope it helps.