Sending Tweets from Arduino through Pachube.com

http://www.tigoe.com/pcomp/code/arduinowiring/1135/#more-1135

from Tom Igoe

(update) I have got this working, exactly as described in the Igoe post – The code is in EthernetPachubeTweeter_tz1.

Essentially, anything that originates from the Arduino is sent to a feed in Pachube. That feed has a datastream which has a trigger which tweets any new data which arrives.

The next thing to try is figuring out whether this can be done as a single line http: request in curl, and therefore, from Max – or any other source

(update) – this is slightly broken – check out the post about converting cosm to xively https://reactivemusic.net/?p=6843]

 

RC car using Arduino with xbee radios

Bi-directional wireless control of motors

tested 5/2014

The potentiometer on the control radio changes the motor speed of the RC car. A potentiometer on the other side controls the brightness of an LED at the controller.

making things talk

The xbee code was adapted from Tom Igoe’s full-duplex Wireless example, chapter 6 – “Making Things Talk” (using an improved version from his blog: http://www.makingthingstalk.com/chapter6/30/#more-30

The xbee radios should be set up as directed – starting on p. 195

Here are the xbee settings:

ATMY ATDL ATDH ATID
Radio 1 1234 5678 0 1111
Radio 2 5678 1234 0 1111

construction

2 stacks:

1) arduino + wireless SD shield + xbee

2) arduino + motor shield + wireless SD shield + xbee  (motor shield hooked to RC car motor)

Each stack has a potentiometer, tx/rx leds, LED for remote brightness control, and batteries.

The motor shield has connections to the RC car motor and 9V battery for power.

code

Code for radio 1: xbee_full_duplex2_radio1.ino

The motor side uses a few lines of code from an instructables.com motor shield tutorial. LED brightness is linked to motor speed – sent out on pin 3 – from the Arduino sketch:

http://www.instructables.com/id/Arduino-Motor-Shield-Tutorial/?ALLSTEPS

code for radio 2 (car): xbee_full_duplex2_radio2_motor.ino

note:

When loading the sketch, set the slide switch on the Wireless-SD shield to ‘USB’ – then switch it back to “micro” to run.

If the controller radio (radio 1) is connected to a computer, open the Arduino serial monitor – or the sketch will block – and nothing will happen.

Download

[wpdm_file id=20]

circuit layout

radio 1
  • pin A0 : input sensor (potentiometer)
  • pin 2 : tx LED
  • pin 3 : rx LED
  • pin 9: test LED (receives brightness data)
radio 2
  • pin A0 : input sensor (potentiometer)
  • pin 3: used internally for motor speed – (the motor is hooked to Channel A on the motor shield)
  • pin 4 : tx LED
  • pin 5 : rx LED
  • pin 10: test LED (receives brightness data)

Re-assign some of the pins from the xbee example so they aren’t on the same ones as the motor shield is using:  Here’s the pin layout that the motor shield uses. i.e.. these are the pins that are used in an Arduino sketch to control each motor function. This project only controls ‘speed’ on channel A (pin 3).

Function Channel A Channel B
Direction Digital 12 Digital 13
Speed (PWM) Digital 3 Digital 11
Brake Digital 9 Digital 8
Current Sensing Analog 0 Analog 1

notes

This Arduino forum post was also helpful – otherwise I would have assumed that the shields were incompatible:

Stacking Arduino Wifi Shield and Arduino Motor Shield

 

Arduino AM radio transmitter

update 6/2014: audio version of the AM transmitter: https://reactivemusic.net/?p=12263

original post

http://dangerousprototypes.com/2011/10/05/am-sofware-radio-using-arduino/

Forum thread which gives a sketch to generate Morse code at 1337khz, with no additional hardware.

http://arduino.cc/forum/index.php/topic,8456.0.html

Tried this sketch and it actually works – local version is:

morse_code_AM_1337_xmtr

Instructions

  • tune AM radio to around 1337 KHz
  • Plug antenna (random length piece of wire) into digital pin 8
  • open serial port set to 9600
  • type in some text and press <return> (but not too much text at once)

Here is a link to a circuit using a crystal oscillator component and a serial port from windows computer to turn it on and off to make cw, also a suggestion (below) to expand it to use audio modulation…

http://www.instructables.com/id/Build-a-computer-controlled-radio-transmitter/?ALLSTEPS

To those wanting to send audio (as in music/voice): You will need an audio transformer. The transformer has 5 leads: 3 on left, 2 on right. The 3 lead side: connect the audio jacks ground on bottom, input on top leaving the middle lead free. The right side: batteries + supply on bottom lead, the top lead connects to the oscillators input pin. What you used as the ground should be the same. Just plug it into the computers “audio out” plug. To transmit music, play it with whatever music player you like. Plug it into a mp3 player/ipod/cd player and take it with you where ever you go. To send voice, plug mic into pc “audio/mic/line in” plug.

More details on voice modulation…

http://www.instructables.com/id/Make-a-simple-AM-transmitter/

 

Cosm with Max

update 6/2014: Cosm is now Xively. Have not re-tested examples below. There is a working Twitter example at internet sensors projects: https://reactivemusic.net/?p=5859

original post

notes

Today I was finally able to get this working. Reading a Cosm (Pachube) feed from curl and from Max. Here is an example that works in curl: (replace API-KEY with actual key)

curl http://api.cosm.com/v2/feeds/76490/datastreams/Power.xml?key=API-KEY

You can get JSON responses by leaving off the .xml extension or replacing it with .json

Its critical to use “key=…” not “X-ApiKey=…” like in the cosm documentation, or you will get permission errors from curl and Max.

I was also able to get the Max project called “pachube report” from Nicholas Marechal to work (requires jasch and cnmat externals)

http://cycling74.com/toolbox/pachube-tools/

This patch uses the typical jit.uldl and jit.textfile objects and some regexp parsing tricks.

Next trick will be creating a feed and sending it to Cosm.

 

 

Google custom search API

notes

API for custom searches from Google…. and a method to spoof the “custom” part of it…

https://code.google.com/apis/console/

https://developers.google.com/custom-search/v1/getting_started

Use this method to build a custom search which searches the whole web…

http://stackoverflow.com/questions/4082966/google-web-search-api-deprecated-what-now

Here is an example of a search using this method with curl – note the API-KEY is removed. You will need to get an API key (see above).

curl "https://www.googleapis.com/customsearch/v1?key=API-KEY&cx=012117491442732664551:egvalbpelhq&q=lectures"

Twitter streaming API examples

Update 5/2014 – all of these examples are broken due to Twitter API upgrade that requires OAUTH instead of user/password. Have left this post – as an example of what you can do. For examples of alternatives, see the internet-sensors projects: https://github.com/tkzic/internet-sensors

— original post —

Here is an example that I actually got working to track mention of dogs… You need to replace USER:PASS with your Twitter login and password. The JSON search results will be written to the file tweets.json.

A running tally of results will be displayed to the console while this is running.

curl https://stream.twitter.com/1/statuses/filter.json -u USER:PASSWORD -d "track=dog" > tweets.json

This one searches for #cats (hashtag)

curl https://stream.twitter.com/1/statuses/filter.json -u USERNAME:PASSWORD -d "track=#cats" > tweets.json

https://dev.twitter.com/discussions/2403

Haven’t tried this one:

Do you have a specific example which doesn’t appear to work? Following Taylor’s advice, I was able to find several streaming entries tracking the “photo” keyword:

  1. curl https://stream.twitter.com/1/statuses/filter.json -d 'track=photo' -u [username]:[password] -# | grep "\"media_url\""

Here is a technique (in the answer) which tracks when the stream gets a hit

http://stackoverflow.com/questions/4786786/using-curl-to-update-mysql-when-curl-spits-out-json

Here are other useful links and examples:

basic curl statuses example, no filters

https://dev.twitter.com/discussions/9911

Look at the post from Matt Seward to do locations…

https://dev.twitter.com/discussions/3779

followers:

https://dev.twitter.com/discussions/4067

tracking:

https://dev.twitter.com/discussions/5520

 

 

curl and oauth

Oauth is the authentication service used by companies like Google and Twitter to protect their API’s.

update 6/2014: For current working examples, see Internet sensors projects: https://reactivemusic.net/?p=5859

original post

notes

A wrapper around curl to support OAuth 2.0: https://github.com/fireteam/curlish

The Google oauth 2.0 tutorial for devices – note: there is a local example in Max teaching examples: google-oauth-readme.txt: https://developers.google.com/accounts/docs/OAuth2ForDevices

How Oauth works.

Web audio from the Soundcloud API

notes

(update) to get your client-id from Soundcloud: From your home page, select more | developers | my apps.

This looks like the easiest way to play streaming content from Soundcloud over the web, Maybe this example could be adjusted to run in Max.

http://stackoverflow.com/questions/13455956/setup-web-audio-api-source-node-from-soundcloud

Example API urls,

this one streams a track: (replace client id with real thing)

http://api.soundcloud.com/tracks/6981096/stream?client_id=CLIENT-ID

This one returns an XML file filled with tracks that can be played:

https://api.soundcloud.com/tracks?client_id=CLIENT-ID

See API reference:

http://developers.soundcloud.com/docs/api/reference#users

(update) Use /resolve to get the user id and user info, given the name – like this:

http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/tkzic&client_id=CLIENT-ID