Arduino INPUT_PULLUP mode

notes

When reading the value of a switch with Arduino, its useful to set the INPUT_PULLUP mode so you don’t need to use an external pullup resistor. By the way, the internal pull-up resistor is 20K ohms.

See this tutorial:

http://arduino.cc/en/Tutorial/InputPullupSerial

If its not clear what a pull-up resistor does,  read the links on this forum post.

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

Everybody has their own way to explain it. I would say that when the switch is open, the pull-up resistor weakly pulls the logic value high, so you don’t get random signal readings.

 

Arduino pachube (cosm) feed for musical stairs

(update) the feed is working – I changed the datastream name from sensor_value to count – and just had it upload a random value every time for testing.

Some initial testing with the Ethernet shield encountered missing libraries when compiling the example sketch which cosm.com provides when setting up an Arduino type feed.

Here is the forum post which explains which libraries are missing:  http://community.cosm.com/node/1694

and here is the helpful quote…

You should try using new official Cosm library for Arduino.

You can download a snapshot zip file here:
https://github.com/cosm/cosm-arduino/zipball/master

You will also need this HTTP library:
https://github.com/amcewen/HttpClient/zipball/master

See here for more details on how to install a 3rd-party
library on different OS:
http://arduino.cc/en/Guide/Libraries

You will find a bunch of usefull examples within the
Cosm library. Please let me know if you have any questions.

Raspberry Pi running Pure Data

example video

http://vimeo.com/50498017

PD extended…

http://log.liminastudio.com/writing/tutorials/how-to-build-pd-extended-on-the-raspberry-pi

and this update

http://puredata.hurleur.com/sujet-8036-build-extended-raspberry-raspbian-wheezy-armf

Running PD on a headless RP

http://guitarextended.wordpress.com/2012/08/28/running-pd-on-a-headless-raspberry-pi/

Here’s a comprehensive install script for PD-extendended from 9/2012

http://iamthemightyjungulator.blogspot.com/2012/09/running-pd-extended-on-raspberry-pi.html

and another

http://puredata.info/downloads/pd-extended-0-43-3-on-raspberry-pi-raspbian-wheezy-armhf

 

 

 

MIDI wireless options

A thought exercise – to come up with various ways of making wireless Midi systems based on projects I’ve already done.

  • any combination of iOS and MacOS devices
  • use touchOSC with above setup
  • Arduino + ethernet shield to wifi router to touchOSC
  • Same as above but using wifi bridge to connect to router*
  • Arduino + wifi shield via UDP*
  • Arduino + wireless SD + xbee to same – one end connected to mac OS device
  • IR emitter/detector pair*
  • Arduino + wireless SD + WiFly rn-xv via UDP*
  • bluetooth* (here’s an app called bluemidi http://www.iosmusician.com/category/bluetooth-midi-on-ios
  • modulated laser pointer and solar panel*
  • convert to audio then use any audio transmission method and convert back to midi*
  • Use RTTY with ham radio*
  • cell phone*

* indicates method not tried yet.

 

 

Arduino with touchOSC and Max

Bi-directional communication from touchOSC to Arduino using an ethernet shield.

In this version, the Macbook is directly connected to the Arduino to provide a serial monitor for status updates. 

How it works: press a toggle, or move a fader, in touchOSC – it sends a message to the Arduino which lights up, or fades, an LED – then sends back an OSC message to touchOSC to light up the toggle button. (note: local feedback should be off for the toggle button in touchOSC. This is the default)

Arduino circuit
  • Use an ethernet shield. 
  • Connect ethernet cable. (I am using a Netgear WNCE2001 ethernet to wiFi adapter)
  • LED is connected to pin 5 and ground. The shorter lead connects to ground.

download

https://github.com/tkzic/max-projects

folder: arduino-osc

files
  • Arduino sketch: OSC_ethernet_test1/
  • touchOSC screen: simple (default) uses /1/fader1 and /1/toggle1
  • Max patch: arduino-osc-ethernet1.maxpat
Arduino files and libraries

***update 1/20/2016 there is a new sketch that uses the OSCuino library from CNMAT instead of ardosc. The sketches should be interchangeable. https://github.com/CNMAT/OSC . The sketch is in a folder called: OSCuino_tz and is based on work by Trippylightning at: http://trippylighting.com/teensy-arduino-ect/touchosc-and-arduino-oscuino/

Copy the OSC_ethernet_test1/ folder to Documents/Arduino. This puts it in the Arduino sketchbook.

The sketch uses: #include <ArdOSC.h>

Download ArdOSC from: https://github.com/recotana/ArdOSC

  1. After downloading, copy the ArdOSC-master folder to /Documents/Arduino/Libraries
  2. Rename the folder to ArdOSC

This post was the key to figuring out how to make this work: http://arduino.cc/forum/index.php?topic=137549.0

Instructions
  1. Connect Arduino to Macbook via USB.
  2. Open the Arduino serial monitor to initialize the ethernet connection and display the IP address.
touchOSC
  1. In touchOSC or Max, set the target IP to the one just displayed in the Arduino serial monitor
  2. From touchOSC (or Max) send on port 8000, receive on port 9000.
  3. Use the default touchOSC layout (simple)
  4. Use /fader1 and /toggle1 to control the LED
Max
  1. Open arduino-osc-ethernet1.maxpat
  2. Set ip address in [udpsend] to the one just displayed in the Arduino serial monitor
  3. Have some fun
Fixed IP address

update 1/2016: A version of the Arduino sketch that uses a fixed IP instead of DHCP is located in the folder: OSC_ethernet_fixedIP/

The IP is set to 192.168.1.177 but you can change it to any valid address on your network.

Arduino sketch
// generic Arduino OSC program 
// works from Max or touchOSC
//
// plug LED into pin 5 (and gnd)
//
// requires ethernet shield
//
// use serial monitor to get the ip address
//
// use these OSC commands (will work from first page of touchOSC simple layout
//
// /1/fader1
// /1/toggle1
//
#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x0B, 0xCE }; //physical mac address
OSCServer server;
OSCClient client;
int serverPort = 8000; //Touch OSC Port (outgoing)
int destPort = 9000; //Touch OSC Port (incoming)
int ledPin = 5; 
int flag=0;
void setup(){
pinMode(2, OUTPUT);
 Serial.begin(9600); 
 Serial.println("DNS and DHCP-based OSC server");
 // start the Ethernet connection:
 if (Ethernet.begin(mac) == 0) {
 Serial.println("Failed to configure Ethernet using DHCP");
 // no point in carrying on, so do nothing forevermore:
 while(true);
 }
 // print your local IP address:
 Serial.print("Arduino IP address: ");
 for (byte thisByte = 0; thisByte < 4; thisByte++) {
 // print the value of each byte of the IP address:
 Serial.print(Ethernet.localIP()[thisByte], DEC);
 Serial.print("."); 
 }
 Serial.println();
 Serial.println();
//start the OSCserver
 server.begin(serverPort);
//add OSC callback function. One function is needed for every TouchOSC interface element that is to send/receive OSC commands.
 server.addCallback("/1/toggle1", &funcOnOff);
 server.addCallback("/1/fader1", &funcFader);
}
void loop(){
if(server.aviableCheck()>0){
 // Serial.println("alive! ");
 } 
}
//When the button on the TouchOSC inteface is pressed, a message is sent from the iDevice
//to the Arduino to switch (togle) the LED on the Arduino on/off
//then a messeage is sent bak from the Arduino to the iDevice to toggle the buttom on/off
void funcOnOff(OSCMessage *_mes){
 float value = _mes->getArgFloat(0); //TouchOSC expects float values
//create new osc message
 OSCMessage newMes;
//set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/1/toggle1");
Serial.println(value);
 if(value < 1.0) {
 digitalWrite(ledPin, LOW);
 }
 else{
 digitalWrite(ledPin, HIGH);
 }
newMes.addArgFloat(value);
//send osc message
 //
 // turn local feedback off on touch-osc control to test this
 client.send(&newMes);
}
// new callback for fader - using same comments
//When the button on the TouchOSC inteface is pressed, a message is sent from the iDevice
//to the Arduino to switch (togle) the LED on the Arduino on/off
//then a messeage is sent bak from the Arduino to the iDevice to toggle the buttom on/off
void funcFader(OSCMessage *_mes){
 float value = _mes->getArgFloat(0); //TouchOSC expects float values
//create new osc message
 OSCMessage newMes;
//set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/1/fader1");
Serial.println(value);
 int ledValue = value * 255.0;
 analogWrite(ledPin, ledValue);
newMes.addArgFloat(value);
//send osc message
 //
 // turn local feedback off on touch-osc control to test this
 client.send(&newMes);

}