electronics

f0dim

this simple addition/hack lets me control the velleman k8064 dc dimmer kit via wireless osc or serial. it's based on an esp8266. the kit is isolated, can dim 220v/110v and is rated for up to 750w loads.
normally one control it using 0-12v but by replacing a resistor (R16) it's possible to do it with the 0-3.3v pwm signal that the esp outputs.

f0dim

i probably should cut some air ventilation holes, but so far it hasn't gotten hot inside.

f0dim_schematics

arduino code for the esp8266...

//f.olofsson2017

// * install OSC from https://github.com/CNMAT/OSC
// * edit where it says EDIT below
// * choose board: "Generic ESP8266 Module" 160 MHz

//osc protocol: /dim pwm fade
//  pwm should be 0.0-1.0
//  fade should be 0.0-1.0 (1.0=instant)
//serial protocol: 253 254 pwmhi pwmlo fadehi fadelow 255
//  pwm hi and lo should be 0-1023
//  fade hi and lo should be 0-1023 (1023=instant)

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>

#define PORT 15551  //receiving osc port
#define PINPWM 0
#define PAYLOAD 4
#define UPDATERATE 16
#define TRIES 100  //how many times try check for wifi connection at startup

const char *ssid = "wifinetwork"; //EDIT your accessPoint network name
const char *password = "wifipassword";  //EDIT your password
const char *espname = "f0dim";
WiFiUDP Udp;
bool wifi;

byte serial_index = 0;
byte serial_data[PAYLOAD];
unsigned long next_time;
float dim = 0.0, dim_target = 0.0, dim_fade = 1.0;

void setup() {
  analogWriteFreq(5000);   //5khz pwm
  Serial.begin(115200, SERIAL_8N1, SERIAL_RX_ONLY);
  pinMode(BUILTIN_LED, OUTPUT);
  pinMode(PINPWM, OUTPUT);
  analogWrite(PINPWM, 0);
  delay(10);
  WiFi.mode(WIFI_STA);
  WiFi.hostname(espname);
  WiFi.begin(ssid, password);
  byte cnt = 0;
  wifi = false;
  while ((WiFi.status() != WL_CONNECTED) && (cnt < TRIES)) {
    delay(100);
    cnt++;
    digitalWrite(BUILTIN_LED, cnt % 2);
  }
  if (WiFi.status() == WL_CONNECTED) {
    Udp.begin(PORT);
    wifi = true;
  }
  digitalWrite(BUILTIN_LED, !wifi); //blue led on if connected to wifi
}

void oscDim(OSCMessage &msg) {
  dim_target = msg.getFloat(0);
  dim_fade = msg.getFloat(1);
}

void loop() {

  //--serial input
  while (Serial.available() > 0) {
    byte val = Serial.read();
    if ((serial_index == 0) && (val == 253)) {
      serial_index = 1;
    } else if ((serial_index == 1) && (val == 254)) {
      serial_index = 2;
    } else if ((serial_index >= 2) && (serial_index < (PAYLOAD + 2))) {
      serial_data[serial_index - 2] = val;
      serial_index++;
    } else if ((serial_index == (PAYLOAD + 2)) && (val == 255)) {
      dim_target = ((serial_data[0] << 8) + serial_data[1]) / 1023.0;
      dim_fade = ((serial_data[2] << 8) + serial_data[3]) / 1023.0;
      serial_index = 0;
    } else {
      serial_index = 0;
    }
  }

  //--osc input
  if (wifi) {
    int packetSize = Udp.parsePacket();
    if (packetSize) {
      OSCMessage oscMsg;
      while (packetSize--) {
        oscMsg.fill(Udp.read());
      }
      if (!oscMsg.hasError()) {
        oscMsg.dispatch("/dim", oscDim);
      }
    }
  }

  //--fading
  if (millis() >= next_time) {
    next_time = millis() + UPDATERATE;
    if (dim < dim_target) {
      dim = dim + dim_fade;
      if (dim > dim_target) {
        dim = dim_target;
      }
    } else if (dim > dim_target) {
      dim = dim - dim_fade;
      if (dim < dim_target) {
        dim = dim_target;
      }
    }
    analogWrite(PINPWM, int(dim * 1023));
  }
}

supercollider example code...

//f0dim can be controlled either via osc or serial
n= NetAddr("192.168.1.105", 15551);
n.sendMsg(\dim, 1.0, 1.0);  //set 100% instantly
n.sendMsg(\dim, 0.5, 1.0);  //set 50% instantly
n.sendMsg(\dim, 0.0, 1.0);  //set 0% instantly
n.sendMsg(\dim, 1.0, 0.001);  //slow fade in
n.sendMsg(\dim, 0.0, 0.0005);  //slower fade out

SerialPort.listDevices;
(
~port= SerialPort("/dev/tty.usbserial123", 115200, crtscts: true);  //EDIT serialport
CmdPeriod.doOnce({~port.close});
f= {|pwm= 1023, fade= 1023|
        Int8Array[253, 254, pwm>>8, pwm%256, fade>>8, fade%256, 255];
};
)

~port.putAll(f.value(1023, 1023));  //set 100% instantly
~port.putAll(f.value(512, 1023));  //set 50% instantly
~port.putAll(f.value(0, 1023));  //set 0% instantly
~port.putAll(f.value(1023, 3));  //slow fade in
~port.putAll(f.value(0, 2));  //slower fade out

~port.close;

udssrKontroll

after many years i finally got around to rebuild one of these boxes.

so this old soviet made device is now a wireless controller that send out osc. there are in total 34 buttons, 16 knobs and an additional rgb status led. it automatically connects via wifi to max or supercollider and run on 5v (usb powerbank).

kicad schematics, arduino firmware, supercollider classes and maxmsp abstractions attached below.

udssrKontroll01

the inside is quite a mess. i use an atmega168 together with six 4051 multiplexers to read all the inputs. the wifi module is an esp8266-01.

udssrKontroll02

AttachmentSize
Package icon udssrKontroll_1.0.zip116.03 KB

f08ch

this box can drive eight speakers (3watt each) and play soundfiles independently from eight micro sd cards (mp3 or wav). an arduino nano is programmed to do sequencing, randomise playback, control volume and set equaliser settings. it all runs on a single 9-12v power supply.

f08ch

very cheap to build. the biggest cost are all the sd cards.

to send commands out to all eight mp3 players, i'm bit banging 9600 baud serial data out on eight digital pins.

f0led

here is another project built around the esp8266. it's a wireless osc controlled 100w led. as the led should act as a stroboscope and not be kept on for long durations of time, i could save space and cost using a smaller sized heatsink. via wifi (opensound control) the led can be turned on/off, the level, attack and release times adjusted etc. there is also a push button trigger input as well as a microphone input. so the strobe can be either triggered manually by the musician, by the sound of the nearby instrument or remotely by a computer.

the strobe also send out osc data from the button and mic so it can in turn be used to trigger additional sounds in the computer.

supercollider example code...

OSCFunc.trace(true)
OSCFunc.trace(false)

n= NetAddr("192.168.1.10", 15555);
n.sendMsg(\led, 0.5, 0.1)   //val, fade
n.sendMsg(\led, 0.0, 0.01)  //val, fade
n.sendMsg(\micMode, 1);  //mic on/off
n.sendMsg(\micFade, 1.0, 0.1);  //mic atk rel
n.sendMsg(\butFade, 1.0, 0.1);  //but atk rel

OSCdef(\oscin, {|msg| msg.postln}, \f0led, NetAddr("192.168.1.10", 15555));

f0led 1

the battery is a 12v sealed lead-acid and i measured up toward 8 amps current draw. it weights about 0.5kg.

f0led schematics

bill of material...

1       ESP8266-01
1       4x2 socket
1       heatsink
2       100uF cap
1       100 resistor
1       10k resistor
1       10k log pot     (reichelt ACP 6-L 10K)
1       regulator       (reichelt LF 33 CV)
1       mosfet          (reichelt IRLZ 34N)
1       mic             (reichelt MCE 101)
4       screwterminals  (reichelt AKL 101-02)
1       12v lead-acid   (pollin 94‑271194)
1       heatsink        (ebay 2.4x2.4inch Aluminum Alloy Heat Sink for 1W/3W/5W/10W LED Silver White)
1       dcdc            (ebay DC DC boost converter Constant Current Mobile Power supply 250W)
1       100w led        (ebay 100W Cool White High Power LED LIGHT SMD chip Panel 9000-10000LM)

thick wires
heat paste
screws and nuts

arduino code...

// * install OSC from https://github.com/CNMAT/OSC
// * edit where it says EDIT below
// * choose board: "Generic ESP8266 Module" 160 MHz

//TODO: gamma correction

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCData.h>

//pin3 (urxd) can do pwm out
//pin2 and pin0 can not do pwm
//pin2 and pin0 have to be 3v3 at powerup

#define ID 10       //EDIT device id (also static ip)
#define PINMIC 0
#define PINBUT 2
#define PINPWM 3
#define PORT 15555
#define UPDATERATE 16
#define TRIES 100  //how many times try check for wifi connection at startup
#define PINGRATE 600
#define STATICIP 1  //optional - 0 or 1

const char *ssid = "mywlan"; //EDIT your accessPoint network name
const char *password = "mypass";  //EDIT your password
const char *espname = "f0led";
const unsigned int outPort = 57120;
#if STATICIP==1
IPAddress ip(192, 168, 1, ID); //EDIT optional static ip
IPAddress gateway(192, 168, 1, 1);  //EDIT optional router
IPAddress subnet(255, 255, 255, 0);
#endif
float micFadeAtk = 1.0, micFadeRel = 0.1; //default fade times
float butFadeAtk = 1.0, butFadeRel = 0.1; //default fade times
float val = 0.0, valTarget = 0.0, fade = 1.0;
unsigned long nextTime;
byte micMode = 0;  //allow mic trigger led on/off
byte micState = 1;
byte butState = 1;
int cnt;
IPAddress outIp;
WiFiUDP Udp;
OSCMessage msgPing("/f0led");
OSCMessage msgMic("/f0led");

void setup() {
  delay(10);
  WiFi.mode(WIFI_STA);
  WiFi.hostname(espname);
  WiFi.begin(ssid, password);
#if STATICIP==1
  WiFi.config(ip, gateway, subnet);
#endif
  cnt = 0;
  while ((WiFi.status() != WL_CONNECTED) && (cnt < TRIES)) {
    delay(100);
    cnt++;
  }
  outIp = WiFi.localIP();
  outIp[3] = 99;  //send to ip x.x.x.99 on same network (e.g. 192.168.1.99)
  Udp.begin(PORT);
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  pinMode(PINMIC, INPUT);
  pinMode(PINBUT, INPUT_PULLUP);
  pinMode(PINPWM, OUTPUT);
  msgMic.add(ID);
  msgMic.add("mic");
  msgPing.add(ID);
  msgPing.add("ping");
}

void oscLed(OSCMessage &msg) {
  valTarget = msg.getFloat(0);
  fade = msg.getFloat(1);
}
void oscMicMode(OSCMessage &msg) {
  micMode = msg.getInt(0);
}
void oscMicFade(OSCMessage &msg) {
  micFadeAtk = msg.getFloat(0);
  micFadeRel = msg.getFloat(1);
}
void oscButFade(OSCMessage &msg) {
  butFadeAtk = msg.getFloat(0);
  butFadeRel = msg.getFloat(1);
}
void sendOscBut(byte val) {
  OSCMessage msg("/f0led");
  msg.add(ID);
  msg.add("but");
  msg.add(val);
  Udp.beginPacket(outIp, outPort);
  msg.send(Udp);
  Udp.endPacket();
  msg.empty();
}
void sendOscMic() {
  Udp.beginPacket(outIp, outPort);
  msgMic.send(Udp);
  Udp.endPacket();
}
void sendOscPing() {
  Udp.beginPacket(outIp, outPort);
  msgPing.send(Udp);
  Udp.endPacket();
}

void loop() {

  //--osc input
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    OSCMessage oscMsg;
    while (packetSize--) {
      oscMsg.fill(Udp.read());
    }
    if (!oscMsg.hasError()) {
      oscMsg.dispatch("/led", oscLed);
      oscMsg.dispatch("/micMode", oscMicMode);
      oscMsg.dispatch("/micFade", oscMicFade);
      oscMsg.dispatch("/butFade", oscButFade);
    }
  }

  //--mic input
  if (digitalRead(PINMIC) == 0) {
    if (micState == 0) {
      micState = 1;
    }
  }

  if (millis() >= nextTime) {
    nextTime = millis() + UPDATERATE;
    if (cnt % PINGRATE == 0) {
      sendOscPing();
    }
    cnt++;

    //--mic input2
    if (micState == 1) {
      micState = 2;
      sendOscMic();
      if (micMode == 1) {
        valTarget = 1.0;
        fade = micFadeAtk;
      }
    } else if (micState == 2) {
      if (digitalRead(PINMIC) == 1) {
        valTarget = 0.0;
        fade = micFadeRel;
        micState = 0;
      }
    }

    //--button input
    if (digitalRead(PINBUT) == 0) {
      if (butState == 0) {
        butState = 1;
        sendOscBut(1);
        valTarget = 1.0;
        fade = butFadeAtk;
      }
    } else {
      if (butState == 1) {
        butState = 0;
        sendOscBut(0);
        valTarget = 0.0;
        fade = butFadeRel;
      }
    }

    //--fade in/out
    if (val < valTarget) {
      val = val + fade;
      if (val > valTarget) {
        val = valTarget;
      }
    } else if (val > valTarget) {
      val = val - fade;
      if (val < valTarget) {
        val = valTarget;
      }
    }

    analogWrite(PINPWM, int(val * 1023));
  }
}

f0led 2

f0led 3

update 171124 added two more photos, a maxpatch and updated the arduino code with static ip option

AttachmentSize
Package icon f0ledtest.maxpat.zip2.07 KB

f0neo

here is how i build super cheap wireless osc controlled rgb ledstrips. the main components for these are an esp8266, a 5v powerbank, a voltage regulator and some leds. the leds i've used so far are the SK6812 RGBW, but it is easy to adapt the arduino code to work with other models like the WS2812B.

f0neo 1

f0neo 2

f0neo schematics

a basic version of the arduino code shown here below. when it starts it creates a soft access point. connect to it with a computer or phone, figure out the ip address of the esp8266 and start sending osc commands to it.

// * install OSC from https://github.com/CNMAT/OSC
// * install Adafruit_NeoPixel from library manager
// * edit where it says EDIT below
// * choose board: "Generic ESP8266 Module"
// * upload and connect to softap with laptop
// * try to send osc messages to ip 192.168.4.1 port 19999
//protocol: [\rgbw, index, red, green, blue, white] example red: [\rgbw, 0, 255, 0, 0, 0]

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCData.h>
#include <Adafruit_NeoPixel.h>

#define PORT 19999
#define NUMNEO 12  //EDIT number of neo pixels in use
#define PINNEO 2

const char *ssid = "f0neo"; //EDIT softAccessPoint network name
const char *password = "mypass";  //EDIT password

WiFiUDP Udp;

//EDIT to match type of leds (see example/Adafruit_NeoPixel/strandtest)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMNEO, PINNEO, NEO_RGBW + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.show();
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);
  Udp.begin(PORT);
}

void rgbw(OSCMessage &msg) {
  pixels.setPixelColor(msg.getInt(0), msg.getInt(2), msg.getInt(1), msg.getInt(3), msg.getInt(4));
  pixels.show();
}

void loop() {
  OSCMessage oscMsg;
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    while (packetSize--) {
      oscMsg.fill(Udp.read());
    }
    if (!oscMsg.hasError()) {
      oscMsg.dispatch("/rgbw", rgbw);
    }
  }
}

attached (zip file) are more elaborate versions of this code - also including maxmsp and supercollider examples and kicad schematics.

AttachmentSize
Package icon f0neo.zip26.95 KB

f0dmx

here is how i built a wireless isolated dmx controller that takes osc input. the box uses an esp8266 to create a wifi access point that one can connect to with a laptop (or phone or whatever). opensound control messages sent to the box are converted into standard dmx commands. multiple clients can be connected and send dmx commands at the same time.

f0dmx 1

f0dmx 2

below is arduino code for the esp8266, the kicad schematics and some supercollider test code.

//Generic ESP8266 Module, 80 MHz

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCData.h>
#include <LXESP8266UARTDMX.h>

#define PORT 19999  //EDIT osc port
const char *ssid = "f0dmx"; //EDIT softAccessPoint network name
const char *password = "mypass";  //EDIT password
#define CHANNEL 3 //EDIT wifi channel

WiFiUDP Udp;

void setup() {
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password, CHANNEL);
  Udp.begin(PORT);
  //pinMode(BUILTIN_LED, OUTPUT);
  ESP8266DMX.startOutput();
}

void dmx(OSCMessage &msg) {
  int channel = msg.getInt(0);
  int value = msg.getInt(1);
  ESP8266DMX.setSlot(channel, value);
}

void start(OSCMessage &msg) {
  ESP8266DMX.startOutput();
}

void stop(OSCMessage &msg) {
  ESP8266DMX.stop();
}

void loop() {
  OSCMessage oscMsg;
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    while (packetSize--) {
      oscMsg.fill(Udp.read());
    }
    if (!oscMsg.hasError()) {
      oscMsg.dispatch("/dmx", dmx);
      oscMsg.dispatch("/start", start);
      oscMsg.dispatch("/stop", stop);
    }
  }
}

bill of material...

1       dcdc            ROE-0505S       reichelt
1       xlr female      XLR 3KU         reichelt
1       optocoupler     6N 137          reichelt
1       ic              SN 75176BP      reichelt
1       box             BOPLA KS 420    reichelt
1       resistor        10K
1       resistor        470
3       resistor        10
1       resistor        120
2       cap             10uF
1       cap             100uF
1       regulator       LF 33 CV
1       micro           ESP8266-01
1       socket          4x2
1       usb cable

f0dmx kicad schematics

example of how to send osc from supercollider to the f0dmx box. make sure you send integers and not floats.

//make sure you are connected to the f0dmx wifi network
n= NetAddr("192.168.4.1", 19999);  //the ip and port of the f0dmx box
n.sendMsg(\dmx, 9, 255)  //dmx channel 9, value 255
n.sendMsg(\dmx, 9, 0)
n.sendMsg(\dmx, 7, 100)  //dmx channel 7, value 100
n.sendMsg(\dmx, 7, 0)

n.sendMsg(\stop)  //usually not needed
n.sendMsg(\start)

AttachmentSize
Package icon kicad schematics27.48 KB

wireless mqtt circuits

i've stared using mqtt for talking to microcontrollers over wifi and here's some code and instructions on how to set up such a system.

there are two programs that have to run in the background. they handle all the communication between the wireless hardware and the client software (maxmsp, supercollider etc). one is mosquitto. mosquitto is a mqtt broker and the central pub/sub hub of the system. the second program is a python mqtt-osc bridge script using the paho client. this python script lets programs like maxmsp or supercollider talk to mosquitto via osc. see the readme.txt included below on how to install and configure these programs.

on the hardware side i build send/receive circuit nodes consisting of a esp8266 module and an arduino pro-mini. these circuits run on 3v, are small and configurable and the parts cost almost nothing. the esp8266 module provides wifi communication and runs a mqtt client (i'm using the adafruit mqtt library), while the pro-mini does the physical inputs and outputs (sensors, leds etc). the two modules talk to each other via serial.
some circuits i've build do 12 digital + 8 analog inputs, while others have 12 leds in combination with 8 analog inputs. but any combination is possible and the number of ins/outs depends on how the pro-mini is programmed. (see portable_promini_ana and portable_promini_led in the zip archive below.)

portable00

portable01

so far i'm really pleased with this new technique. it seems to scale well and work more reliable than what i used before (sending raw osc via cc3000 or esp8266).

AttachmentSize
Package icon portable.zip16.11 KB

syntjuntan

i got to design and build version 2 of syntjuntan's sewable synthesizer circuit. for this version they wanted to add an on-board amplifier that could drive a passive speaker element.

the circuit now has three schmitt triggers and can run on 3-12V. the amplifier is the classic lm386 and the connector pads around the board are made to fit needle and conductive thread as well as being crocodile friendly.

there are some options as standard through-hole soldering pads (a fourth schmitt trigger and x10 extra gain). the circuit can also be used as a standalone audio amplifier - just ignore the schmitt triggers and connect your own signal to the in pad.

anyway, lots of fun mass producing this and in the process i learned how to do hot-air smd soldering with stencil and solder paste plus got to know kicad a bit better.

i also built a test rig with an arduino and some pogo pins. it both scans for short-cuts and tests the sound.

syntjuntakrets 2 2

syntjuntakrets 2 4

syntjuntakrets 2 5

Pages

Subscribe to RSS - electronics