Solid State Tesla coil – PiZero/RPI2 software setup

Needs updating to newest Raspian image, due to serial changes on some models, currently works with an image from November 2016

The Software is written in C and impliments tes functions and a background script that interfaces with the Lunux MIDI ALSA system and the I2C bus with the I2C Driver attached.

The Background script (I2C-MIDI2)  implements the following

  • Reads Config  file (midi.conf) to get settings for I2C ports and midi channels to I2C addresses and max ontimes for the coil.
  • Listen on a ALSA MIDI port for midi messages
  • Decode the messages and convert them into note values for the I2c driver to process
  • Assign ontime values for the tesla coil(s)
  • Support Update (re read conf) and Stop Signals
  • Send All OFF to I2C if no midi present for >3 seconds

Currently the code is HORRENDUS, when I’ve stopped changing it, cleaned it up and commented it, I will release it.

If anyone wants a bleeding edge copy, please contact me.

For the system to run you will need the ALSA and WiringPi Packages for your RPI, the install is detailed below.

Update your PI

apt-get update
apt-get upgrade

Enable I2c interface

sudo raspi-config

Now complete the following steps :

  • Select “8 Advanced Options”
  • Select “A7 I2C”
  • Select “Yes”

The screen will ask if you want the interface to be enabled :

  • Select “Yes”
  • Select “Ok”

The screen will ask if you want the module to be loaded by default :

  • Select “Yes”

The screen will state the module will be loaded by default :

  • Select “Ok”
  • Select “Finish” to return to the command line

When you next reboot the I2C module will be loaded.

Download TeslaMidi Source

Start in the home directory.

cd /home

copy all of the program files into home (Not currenty shared, if you are interested email me and ill send you the latest release)

make a midi directory

mkdir midi

copy all of the midi files into the /home/midi directory.

 

Get librarys and dependencies

apt-get install gcc git-core libconfig-dev libasound2

apt-get install libasound2-dev i2c-tools

Get WiringPi

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

Configure I2C
un-comment
dtparam=i2s=on
and add line
dtparam=i2c1_baudrate=200000 (or 50000)
in /boot/config.txt

 

Compile Sources

from the /home directory

make

Take a look here for more details about the I2C clock streaching issues.

Example config file


i2cchan1 = 0x2A;
i2cchan2 = 0x2B;
midichannel = 1;
midioctive = 0;
mididelay = 0;
plength = 75;
midichannel2 = 2;
midioctive2 = 0;
mididelay2 = 0;
plength2 = 75;
TcDebug = 0;

 

Running the code.

To make things easy I have created scripts for starting up the background process and seting up the ALSA midi routing

set-midi is a c program that let me set the midi.conf file and signals an update to the running i2c-midi background program.

aconnect is an ALSA program that allows the mapping of a midi port to a virtual port.  The midi2-i2c monitors port 14, ports 128 and 129 are used as “switchboards” to connect other MIDI devices.

midi-pid is a file that is created to point the set-midi to the process ID of the background midi2-i2c. It also allows a quick check to see if the background program is running.

Start with defailts (ready to play midi)


#map midi ports
aconnect -x
aconnect 14 128
aconnect 14 129

#start midi background
killall midi2-i2c
rm midi-pid
./midi2-i2c &
sleep 3

echo ' '
echo '***************'
echo '* MIDI READY  *'
echo '***************'
echo " "

Start with Midi from Keyboard


#remove old instance
killall midi2-i2c
rm midi-pid
sleep 1

#restart
./midi2-i2c &
sleep 2

#set plength
./set-midi plength 150

#set channel
./set-midi midi2 1 0 0 1 0 0

#map midi ports
aconnect -x
aconnect 20 128

echo ' '
echo '***************'
echo '*  KBD READY  *'
echo '***************'
echo " "

Play a midi file script

notes

set-midi plength2 150 – Set max pulse length of I2C port 2 to 150uS

set-midi midi2 3 0 0 6 0 0 – Set midi channels to 2 & 6 (0’s are for future use)

aplaymidi –port 14  midi/brand3.mid – plays a midi file on port 14


./set-midi plength 200
./set-midi plength2 150
./set-midi midi2 3 0 0 6 0 0
aplaymidi --port 14  midi/brand3.mid

Back to pizero tesla coil project main page