electronics

redThermoKontroll2

for my upcoming solo at the sound of stockholm festival, i decided to rebuild my main wireless controller. previously it used a nordic nRF24L01+transceiver as radio module, but the range wasn't great and communication often broke down during live performances. i don't know much about these things, but i guess that when the audience bring in mobile phones the radio spectrum quickly fills up.

so i constructed a new circuit from scratch and while i was at it also reworked the resistor ladders and other cabling inside the box. now it's using wifi. the new radio module i installed in the controller box is adafruit's great CC3000 WiFi Breakout, and as receiver i use a small tl-wr703n wifi router running openwrt.
the wireless range is now excellent and everything is a lot more stable. i could also drastically reduce the amount of data being sent by fixing the resistor ladders.

circuit... (basically just one atmega382p, a 16 channel adc, voltage divider resistors and the wifi module)

redThermoKontroll2-00

inside...
redThermoKontroll2-01

outside...
redThermoKontroll2-02

100ohm resistor ladder...

redThermoKontroll2-03

below are parts list, schematics, firmware and a supercollider class.

redThermoKontroll (wifi version) parts list:

1 4067 multiplexer
1 atmega328p
1 16mhz crystal
2 27p
1 socket 2x14 (28pin)
1 adafruit cc3000 module
1 1x9 pin header
1 1x10 pin header
1 1x8 pin header
1 1x5 pin header

1 resettable fuse 1a
1 zener diode 5.6v
1 0.1uF cap
1 100uF electrolytic cap
1 470uF electrolytic cap

10 220, 270, 330, 680, 1k, 2, 10k resistors
1 220 resistor for led

1 power jack
1 ldr
1 red led

lots of 100ohm resistors for resistor ladders

redThermoKontroll-schematics2

//redThermoKontroll2
//redFrik 2013 gnu gpl v2
//updated 150920 - automatically send to IP x.x.x.99 (constructed from given DHCP IP)

//make sure to use Paul Stoffregen's branch of the Adafruit_CC3000 library
//and cc3000 firmware 1.24 (1.11.1)
//select board UNO and upload to a ATMEGA328P chip (using a usbtinyisp programmer)
//test in terminal with command: nc -ul 58100

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>

#define WLAN_SSID       "xxx"
#define WLAN_PASS       "yyy"
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define PORT            58100
#define DELAY           10
#define PINGRATE        2000

#define ADAFRUIT_CC3000_IRQ   3   //mega328 pin 5
#define ADAFRUIT_CC3000_VBEN  8   //mega328 pin 14
#define ADAFRUIT_CC3000_CS    10  //mega328 pin 16
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBEN, SPI_CLOCK_DIVIDER);
Adafruit_CC3000_Client client;

uint8_t buf[16];
byte last[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

byte cnt = 0;
unsigned long time;

void setup(void) {
  Serial.begin(115200);  //debug

  //--pins
  pinMode(7, OUTPUT);         //led
  pinMode(6, OUTPUT);         //4067 d (DDD6)
  pinMode(5, OUTPUT);         //4067 c (DDD5)
  pinMode(4, OUTPUT);         //4067 b (DDD4)
  pinMode(2, OUTPUT);         //4067 a (DDD2)
  pinMode(A5, INPUT);         //4067 x
  pinMode(A4, INPUT_PULLUP);  //capa1 (right)
  pinMode(A3, INPUT_PULLUP);  //capa0 (left)
  pinMode(A2, INPUT_PULLUP);  //swiUp (up)
  pinMode(A1, INPUT_PULLUP);  //swiUp (down)
  pinMode(A0, INPUT_PULLUP);  //swiOn

  //--wifi
  flash(1);
  Serial.println(F("Starting"));
  if (!cc3000.begin()) {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while (1);
  }
  flash(2);
  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while (1);
  }
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected!"));
  flash(3);
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP()) {
    delay(100); // ToDo: Insert a DHCP timeout!
  }
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  while (!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) {
    Serial.println(F("Unable to retrieve the IP Address!"));
    delay(100);
  }
  Serial.print(F("\nCC3000 IP Addr: "));
  cc3000.printIPdotsRev(ipAddress);
  //the following sets receiver to x.x.x.99 and assume cc3000 will never get exactly that IP itself
  ipAddress = cc3000.IP2U32(ipAddress >> 24 & 255, ipAddress >> 16 & 255, ipAddress >> 8 & 255, 99);
  Serial.print(F("\nReceiver IP Addr: "));
  cc3000.printIPdotsRev(ipAddress);
  client = cc3000.connectUDP(ipAddress, PORT);

  //--osc message [/tk2, index, value]
  buf[0] = 47;   // /
  buf[1] = 116;  // t
  buf[2] = 107;  // k
  buf[3] = 50;   // 2
  buf[4] = 0;
  buf[5] = 0;
  buf[6] = 0;
  buf[7] = 0;
  buf[8] = 44;   // ,
  buf[9] = 105;  // i
  buf[10] = 0;
  buf[11] = 0;
  buf[12] = 0;   //msb - index
  buf[13] = 0;   //
  buf[14] = 0;   //
  buf[15] = 0;   //lsb - value
}

void loop(void) {
  byte val;

  //--analog inputs
  for (byte i = 0; i < 13; i++) {
    setChan(i);
    delay(1);                //not sure if needed
    val = analogRead(A5) >> 2; //from 10 to 8 bits
    if (val != last[i]) {
      sendOsc(i, val);
      last[i] = val;
    }
  }

  //--digital inputs
  val = PINC & 0b00011111;
  if (val != last[13]) {
    sendOsc(13, val);
    last[13] = val;
  }

  //--ping
  if (millis() - time > PINGRATE) {
    sendOsc(127, 0);      //ping
    time = millis();
  }
}

void sendOsc(byte index, byte val) {
  buf[12] = index;
  buf[15] = val;
  if (cnt++ % 2 == 0) {   //toggle red led
    PORTD &= ~_BV(DDD7);
  }
  else {
    PORTD |= _BV(DDD7);
  }
  client.write(buf, sizeof(buf));
  delay(DELAY);
}

void setChan(byte index) {
  switch (index) {
    case 0:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 1:
      PORTD |= _BV(DDD2);                                               //high
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 2:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD |= _BV(DDD4);                                               //high
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 3:
      PORTD |= _BV(DDD2);                                               //high
      PORTD |= _BV(DDD4);                                               //high
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 4:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD |= _BV(DDD5);                                               //high
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 5:
      PORTD |= _BV(DDD2);                                               //high
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD |= _BV(DDD5);                                               //high
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 6:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD |= _BV(DDD4);                                               //high
      PORTD |= _BV(DDD5);                                               //high
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 7:
      PORTD |= _BV(DDD2);                                               //high
      PORTD |= _BV(DDD4);                                               //high
      PORTD |= _BV(DDD5);                                               //high
      PORTD &= ~_BV(DDD6);                                      //low
      break;
    case 8:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD |= _BV(DDD6);                                               //high
      break;
    case 9:
      PORTD |= _BV(DDD2);                                               //high
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD |= _BV(DDD6);                                               //high
      break;
    case 10:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD |= _BV(DDD4);                                               //high
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD |= _BV(DDD6);                                               //high
      break;
    case 11:
      PORTD |= _BV(DDD2);                                               //high
      PORTD |= _BV(DDD4);                                               //high
      PORTD &= ~_BV(DDD5);                                      //low
      PORTD |= _BV(DDD6);                                               //high
      break;
    case 12:
      PORTD &= ~_BV(DDD2);                                      //low
      PORTD &= ~_BV(DDD4);                                      //low
      PORTD |= _BV(DDD5);                                               //high
      PORTD |= _BV(DDD6);                                               //high
      break;
  }
}
void flash(int num) {
  for(byte i= 0; i<num; i++) {
    digitalWrite(7, HIGH);
    delay(100);
    digitalWrite(7, LOW);
    delay(100);
  }
}

AttachmentSize
Package icon redThermoKontroll2-supercollider.zip8.59 KB

arduino programming via soundcard

with lots of study of the AudioBoot_V2_0 java code by chris at roboterclub-freiburg.de, i managed to write supercollider code for uploading sketches to an arduino via the soundcard. no ftdi chip needed!
it's a very cheap solution for programming barebone arduinos (well, atmega168 microcontrollers really). you only need a few resistors, a capacitor and a mega168. the only difficult part is to 'initialize' this microcontroller by burning the special bootloader on to it. this requires an avr programmer of some sort (STK500, USBtinyISP etc).

the preparation steps are as follows...
1. burn the bootloader on to a mega168
2. build the barebone circuit
3. prepare the arduino ide
4. install the RedArduino class

after that one can compile hex files in the arduino ide and upload them using supercollider and a standard audio cable.

1. burn the bootloader on to a mega168

the trick behind all this is the special 'sound enabled' bootloader that i found here... http://www.hobby-roboter.de/forum/viewtopic.php?f=4&t=127. i downloaded the AudioBoot_V2_0.zip file and used my stk500 avr programmer together with the great avr crosspack. the terminal command i used for burning the bootloader was the following...

avrdude -v -p m168 -b 115200 -P /dev/tty.PL2303-000013FA -c stk500v2 -U flash:w:/Users/Stirling/arbeten/sc/scAudioino/AudioBoot_V2_0/Atmega_Source/chAudioBoot_ATMEGA168_IN_PD1_LED_PB5.hex -U lfuse:w:0xE2:m -U hfuse:w:0xDF:m -U efuse:w:0xFA:m

2. build the barebone circuit

then i built a minimal and barebone arduino circuit after the schematics found here... http://www.hobby-roboter.de/forum/viewtopic.php?f=4&t=128&p=531. again credit to chris.

this is the schematics i drew...

and here the resulting circuit...


i run it off 4,5v (3 batteries) but it could also be powered from the usb port.

3. prepare the arduino ide

to compile hex files for this barebone arduino, i needed to set up a custom board in the arduino ide. one way to do this is to create a new text file called boards.txt and put it inside a new folder in the arduino/hardware folder. on mac osx that could be something like ~/Documents/Arduino/hardware/BareBones/boards.txt. the boards.txt should contain the following...

minimal168.name=ATmega168 bare bone (internal 8 MHz clock)
minimal168.upload.speed=115200
minimal168.bootloader.low_fuses=0xE2
minimal168.bootloader.high_fuses=0xDD
minimal168.bootloader.extended_fuses=0×00
minimal168.upload.maximum_size=16384
minimal168.build.mcu=atmega168
minimal168.build.f_cpu=8000000L
minimal168.build.core=arduino:arduino
minimal168.build.variant=arduino:standard

then restart the arduino ide and under boards there should be a new option with mega168 and 8mhz internal clock. i make sure this board is selected every time before compiling hex files for sound uploading.
another thing that needs to be done is to enable 'verbose compile' in the arduino ide preferences. that will print out the file path of the hex file each time you compile a sketch.

4. install the RedArduino class

i wrote a couple of classes for supercollider to help with the encoding and signal generation of hex files. they're found in my redSys quark (under redTools) and are most easily installed from within supercollider itself with these commands...

Quarks.checkoutAll;             //update
Quarks.install("redSys");       //install. recompile after this

there are two helper classes and one main class. the RedIntelHex class parses hex files and RedDifferentialManchesterCodeNegative helps to encode the signal as differential manchester code. the main class RedArduino figures out the paging of data and generates a bit stream that is played back using demand rate ugens.

uploading

i upload sketches by compiling them in arduino ide (click verify - not upload) and copy&paste the file path of the resulting hex file into supercollider and the RedArduino's read method. i connect the left sound output channel to the barebone arduino, put my mac volume to ~80%. last i press the reset button on the circuit and quickly (within seconds) call the upload method in sc. the led should blink slowly directly after a reset, and fast when receiving data.

here's a video demonstrating how to do it. i'm just uploading the simple Blink example. near the end you will also hear how that sounds.

audioino from redFrik on Vimeo.

there's also some sc code i wrote here that will do the same thing but without the need of the redSys quark classes.

trash or treasure

some weeks ago i found a canon pixma MP510 on the street. a "Photo All-in-One with economical single inks that prints, copies or scans in colour". someone had thrown it away regarding it as a piece of junk. i saw a pile of gold.

taking it apart i got...
* four really nice motors: two steppers and two dc motors
* a 33x25 cm piece of glass
* boxed and reusable 220v powersupply
* a small lcd colour display
* a scanner head
* some leds
* five infrared sensors (paper sensors)
* lots of screws and springs
* wire and cog belts
* some switch buttons
* two usb jacks
* various other components



alike http://makezine.com/projects/dont-waste-ewaste-unmaking-a-canon-printerscannerfax-into-parts/

usb soundcards mod

to save a bit of power (and annoyance), i de-soldered the leds on two usb soundcards. i use these soundcards for battery driven projects (beaglebone black) and every milliamp i can save counts.
the logilink soundcard had two easily removable leds. the red one indicated that the soundcard was connected and had power, and the green one started to blink when the card was in use (driver activated). both functions i can easily live without.
the blue '3d-sound' card had a very tiny surfacemount led that i removed using two soldering irons.

here some before and after photos...




btw, i'd stay away from the logilink. it has a problem with audible noise coming from the pwm signal of the green blinking led. if you connect a mic like i'm doing, a beep beep beep kind of sound leaks into the mic. and removing the led doesn't help. maybe there's something in the software driver to control it, but i doubt it.

hats

a tiny circuit i designed and built in five copies for dancer Raffaella Galdi. with the help of a small magnetic sensor this circuit makes it possible to start and stop sound coming from a mp3 player. because the five circuit boards, speakers and mp3players are mounted inside pointy hats, the electronics had to be light and draw very little current from the battery.
for the sound volume control i used a vactrol (ldr+led) and the timing and fade in/out logic are encoded in the firmware of a little microcontroller (ATtiny45). to save battery, the tiny45 is put to sleep and is only active when the magnetic reed sensor is triggered. i used the great JeeLib.h for controlling the sleep cycles of the microcontroller.

schematics, firmware and partslist attached below.

AttachmentSize
Package icon hats.zip29.15 KB

broderi

wireless sensor for embroidery.

the sensor is a tilt compensated compass i.e. a 3d accelerometer in combo with a 3d magnetometer. compared to my other wireless boxes, this one runs on 3.0V (two AAA batteries) and not 3.6V. this due to the LSM303DLH sensor's lack of onboard voltage regulators and 1.8V i2c data lines.
the mega168 has an arduino sketch loaded as firmware and is using the internal 8mhz oscillator. so the circuit is pretty minimal.

as part of the project knyppel with ann rosén.

schematics, arduino firmware, partslist, maxpatches, supercollider class attached.

AttachmentSize
Package icon broderi.zip57.14 KB

soft modem

this summer i build 8 small circuits that can control a bunch of leds (6 channels pwm) from basically any idevice or android phone. the circuit connects to the audio jack of the phone and uses the right channel to send data commands (in the form of a modem signal).

we use rjdj (and pdlib, supercollider, etc) to generate the data signal on the phone in realtime. and it's relatively easy to connect for example the built-in accelerometer in the phone to control some leds, or to run amplitude/pitch tracking on the microphone and let that flash some leds.

the circuits will be used in the rhyme research project as well as in the upcoming e-textile workshop in oslo (oct 2011).

the design is based on SoftModem by arms22. attached below are my schematics, pd fsk abstraction and arduino firmware.

the modem signal is generated using frequency-shift keying and here's how to do that in supercollider...

(
c= "how are you?";
{var t= 1/1225; var m= Duty.ar(Dseq([t*100]++t.dup(11*c.size)), 0, Dseq([1]++c.ascii.collect{|cc| [0]++(cc.asBinaryString.ascii-48).reverse++[1, 1]}.flat), 2); SinOsc.ar(m*(7350-4900)+4900)!2}.play(fadeTime:0);
)

this will send the characters "how are you?" at a baudrate of 1225. this is of course not a valid command for the circuit above, just something to demonstrate how it sounds. below is an mp3...


AttachmentSize
Package icon softModem.zip61.64 KB

Pages

Subscribe to RSS - electronics