chipKIT® Development Platform

Inspired by Arduino™

CHIPkit port of Twitter Lib. (tweeting chipkit)

Created Mon, 12 Mar 2012 00:02:52 +0000 by Addidis


Addidis

Mon, 12 Mar 2012 00:02:52 +0000

EDIT :

**I think I have the Lib ported over and working if any one wants to give it a test.**The examples show the changes that need to be made to the arduino examples to make it work. (defines and that stuff).

The two examples that come with the lib are ported.

https://docs.google.com/open?id=0B8NxkJPWMNcZeXVtVFpEZGlTbWEtcGxOaEVDRXNrdw

Click the link, window pops open, click file -> download. Stick it in mydocs/mpide/libraries and unzip to here.

/Edit There is a spam post that is not being removed so I figured I would attach the library to the first post.

I got interested in the tweeting devices so I tried to port over the a simple post example.

It was pretty easy but I figured I would post it up here it uses the chipkit max32 and network shield. I just slapped the network shield on after making sure the power selector jumper was in regulate position, connected a power supply plugged in the cable. Load this up and it should work.
It uses the lib from the chipkit network shield page on digilent's site. It was created from the webclient example. I didnt change some variables or remove un-needed parts so a diff should work well to see what was changed to learn.

The first attempt at this used the code at the link below. It explains how to get a token which you will need to fill in. You should be able to follow the arduino forum with this sketch instead of the one they use.

http://tronixstuff.wordpress.com/2011/03/08/moving-forward-with-arduino-chapter-30-twitter/

http://www.arduino.cc/playground/Code/TwitterLibrary

The code below will load up , takes like 10 seconds. Open the serial port and set it at 115200. It should connect do some stuff (send a tweet using your token) then disconnect.

#include <chipKITEthernet.h>
//Chipkit port of the "simple post" example. 

/*
  This sketch is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This sketch is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this sketch; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
/************************************************************************/
/*  Revision History:							*/
/* 									*/
/* 8/08/2011 Digilent Inc. (KeithV)					*/
/* Updated for use with the chipKIT Max32 and chipKIT Network Shield	*/
/*									*/
/************************************************************************/

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 */

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
//You might need to put your mac below. 
byte mac[] = {  0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte ip[] = { 192,168,1,5 };
byte gateway[] = { 192,168,1,1  };
byte subnet[] = { 255,255,255,0 };
byte dns1[] = {0,0,0,0};
byte dns2[] = {0,0,0,0};
char token - "Put your token here";
char msg[] = "Hello world from chipkit";
//byte server[] = { 173,194,33,104 }; // Google
const char * szGoogle = "arduino-tweet.appspot.com";
// const char * szGoogle = "74.125.53.106";

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
Client client(szGoogle, 80);

void setup() {
  // start the Ethernet connection:

//  Ethernet.begin();                                   // DHCP is used, default ENCX24J600 (ENC24J60) MAC address 
//  Ethernet.begin(mac);                                // DHCP is used
//  Ethernet.begin(mac, ip);                            // Static IP, gateway equal to the IP with the last byte set to 1 => IP[3].IP[2].IP[1].1
//  Ethernet.begin(mac, ip, gateway);                   // default subnet 255.255.255.0
   Ethernet.begin(mac, ip, gateway, subnet);           // default dns1 is equal to gateway, some router/gateways act as DNS servers
//  Ethernet.begin(mac, ip, gateway, subnet, dns1);     // default dns2 is 0.0.0.0
//  Ethernet.begin(mac, ip, gateway, subnet, dns1, dns2);

  // start the serial library:
  // PLEASE NOTE THE SERIAL MODEM SPEED!
  // the speed is not the typical 9600; this is because
  // the serial monitor can not keep up with the page update
  // and will drop characters, the serial monitor must run faster
  // When you open the serial monitor, go to the bottom right and select 11500 as the speed
  Serial.begin(115200);
  
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect()) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("POST http://" "arduino-tweet.appspot.com" "/update HTTP/1.0");
    client.print("Content-Length: ");
    client.println(strlen(msg)+strlen(token)+14);
    client.println();
    client.print("token=");
    client.print("token");
    client.print("&status=");
    client.println(msg);

    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      Ethernet.PeriodicTasks();
  }
}

Addidis

Wed, 14 Mar 2012 23:53:10 +0000

I think I have the Lib ported over and working if any one wants to give it a test. The examples show the changes that need to be made to the arduino examples to make it work. (defines and that stuff).

The two examples that come with the lib are ported.

https://docs.google.com/open?id=0B8NxkJPWMNcZeXVtVFpEZGlTbWEtcGxOaEVDRXNrdw

Click the link, window pops open, click file -> download. Stick it in mydocs/mpide/libraries and unzip to here.


Jacob Christ

Thu, 15 Mar 2012 04:13:10 +0000

This is cool, I can't wait to try it. I've seen other such projects like this but I'm at a loss as to what you would do with something like this. It seems like automated broadcast tweets would just be noise in the stream.

The one thing I can think of that would be nice is if a bus stop could tweet that a bus is at it. That way I could follow a bus stop prior to where I was going to get on that would let me know the bus will be here soon.

Jacob


Addidis

Thu, 15 Mar 2012 06:14:37 +0000

Networked Geiger counters. Have them all report to one place and then display the data. If you got enough of them up you could gather some useful data.

Turn your ac on from the car on the way home. Etc.

I suppose its only noise if you listen to it :)

I cant sleep and came up with this : Lets say your a boss at work and have a lazy employee who is always late. Set up a chipkit +network shield and a button. If the employee doesn't get there in time to push the button it tweets that he was late :)

Another idea is an rfid / nfc id system to guard your hackerspace door. Make it tweet who showed up so others can come in too.

PS in chicago the busses are tracked by gps. It doesnt work as well as it should but you can log in and sorta track your buss.