BeetBox


17 posts
by scottgarner » Sat Dec 15, 2012 2:28 pm
Hey all,

I wanted to share my first big Pi-based project. The BeetBox a simple instrument that allows users to play drum beats by touching actual beets. It is powered by a Raspberry Pi with a capacitive touch sensor and an audio amplifier in a handmade wooden enclosure.

Image

A full write-up, along with a demonstration video, can be seen on my site.

-S
Posts: 1
Joined: Wed Nov 14, 2012 11:33 pm
by jamesh » Sat Dec 15, 2012 4:51 pm
You know, when I first saw the post title, I was thinking - he's misspelt that.

BUT NO! It's real beet! And since the roads where I live are currently covered in beet droppings.....I'm a fan already!
Moderator
Moderator
Posts: 10528
Joined: Sat Jul 30, 2011 7:41 pm
by malakai » Sat Dec 15, 2012 5:21 pm
So nice very creative it seems as though you had 2 assignments and managed to do it in 1

Why is there no popping sound at the end of the beats I avoid using the speaker jack but when I did everything always caused the popping sound. Is it dubbed over? It doesn't seem like it is.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)
User avatar
Posts: 1383
Joined: Sat Sep 15, 2012 10:35 am
by gritz » Sat Dec 15, 2012 6:23 pm
*insert root access joke here*

Brilliant! 8-)
Posts: 449
Joined: Sat Jan 28, 2012 2:33 am
by N8HWV » Sun Mar 31, 2013 6:00 am
Hello,
I'm trying to duplicate your BeetBox, and get the following error when I execute the code:

pi@raspberrypi ~/python_prog $ sudo python beetbox.py
Traceback (most recent call last):
File "beetbox.py", line 22, in <module>
mpr121.setup(0x5a)
File "/home/pi/python_prog/mpr121.py", line 74, in setup
bus.write_byte_data(address, ELE_CFG, 0x00)
IOError: [Errno 5] Input/output error

I left all the pull-up resistors connected on the Sparkfun mpr121; is that the problem?

When I do a "sudo i2cdetect -y 0" I do see the mpr121 on 5a

What am I missing?
Thanks,
Nate
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by N8HWV » Mon Apr 01, 2013 6:13 pm
Think I've answered my own question:
In the mpr121.py file:
"bus = smbus.SMBus(1)" is for version 2 of the Pi
"bus = smbus.SMBus(0)" is for version 1 of the Pi

Referencing this blog: http://www.skpang.co.uk/blog/archives/575
Great info.

Can't wait to actually try the above, and see if it solves my problem.

Have learned so much by trying to duplicate this project.
"Never give up."
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by N8HWV » Tue Apr 09, 2013 11:18 am
Got it going.

For some reason, when I ran the program from the IDLE gui, I would get one error, and when I would try to run it from the terminal, I would get no audio, but could see the "touched/release" message.

Honestly I don't know what finally got it working, but it just started working after trying, and trying, and trying different things. I guess the final thing was changing the "...pre_init" setting to 1 channel instead of 2, and getting my .wav files solid. (Even though it still works now that I changed the channel setting to 2)

For anyone else trying to duplicate the BeetBox-
I believe Pygame only works with Python 2.7
Make sure you read the Pygame 'mixer' section at http://www.pygame.org/docs/ref/mixer.html
Verify your .wav files are good, in the right format, and named consistently in your code.
Your .wav file needs to be in the same directory as beetbox.py
Try the command "aplay filename.wav" from the command line; it should play your sound.

The file "mpr121.py" should be in the same directory as "beetbox.py"
Study the mpr121 datasheet: https://www.sparkfun.com/datasheets/Com ... MPR121.pdf
I left the pull-up resistors connected on the Sparkfun breakout board.
When running beetbox.py, use this command: sudo python beetbox.py, or sudo -s python beetbox.py

Study the GPIO pins, and know whether you have a version 1 or version 2 setup (and see my previous post regarding i2c bus 1 vs 0 setting in the "mpr121.py" file)
Essential GPIO info: http://elinux.org/RPi_Low-level_periphe ... re_hacking
More GPIO info: http://code.google.com/p/raspberry-gpio ... i/Examples

Your electrode wires should be kept to a minimum length. I have mine at the end of a six? foot flat cable, and it only kinda works (false releases and re-triggers, mainly, and had to adjust the touch threshold down to 5 to get a trigger).

Troubleshoot by getting one piece working at a time, and testing. For example, I wrote a tiny program just to play sounds with Python and Pygame. Until that was working, no sense in moving forward.

Without the tutorials on Adafruit.com and MagPi.com, and the variety of info posted on the web regarding RPi, I never would have got this project working.

Again, thank you Scott, for the great idea, and sharing your code.
n8telyons@gmail.com
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by H00PD0GG » Thu Apr 11, 2013 5:06 pm
somebody please help :-s
I have designed and made a board consisting of an mcp20317 and an mpr121 with two voltage regulator circuits for my 3v3 and 5v0. I can see the mcp23017 and the mpr121 on i2c, i am trying to make a program very simular to the beetbox triggering audio with relay outputs for switching lights. I have managed to run beetbox.py and can see the mpr121's inputs being triggered when i touch them, the issue i have is the audio, ive noticed in the nano editor looking at the beetbox.py the audio is triggered from pygame. I cannot seem to find any directory or file called pygame, i have a python_games but cannot find the .wav files that are mentioned in the beetbox.py program. I guess i must have a pygame somewhere as the beetbox.py runs with no errors saying cannot find ........ if i go into python games on the pi's desktop and launch a game telling the audio to force headphones i then manage to get a horrible clicking when the mpr121's triggers are triggered.
I am using the latest version of the Raspberry pi with Raspian Wheezy.
I have only been using Linux for two days so am a complete novice and dont really have a clue what im doing.
Can anybody help me please ?
Posts: 6
Joined: Wed Apr 10, 2013 1:00 pm
by wesaskif » Wed May 01, 2013 11:09 pm
N8HWV,
I've also been trying to replicate the beetbox. I think my code will work fine, but I cannot test it without the proper hardware implementation, and I've never worked with hardware. I'm using the Pi with a Cobbler connected to a breadboard. What wiring setup did you use?

Right now this is what I have:

http://imgur.com/gtirsLg

3.3v GPIO to positive on breadboard
GND GPIO to negative on breadboard
Wires connecting the power and ground to their respective slots on the mpr121
Wire from Pin 7 (CE1) to SDA to serve as interrupt/data reader
Wires from electrodes

The mpr121 isn't even showing up in i2cdetect
Posts: 1
Joined: Wed May 01, 2013 10:58 pm
by N8HWV » Thu May 02, 2013 3:04 am
Hi there.
From your photo I see a few problems. But first, you need to know if you have version 1 or version 2 of the RPi. That w determine whether your bus address is 0 or 1. Read my previous post for more on that.

More importantly, doubt you are getting good electrical connection on your mpr121 breakout board with the jumpers poked thru the holes. You will want to solder some header pins to the holes to make good electrical connections. See www.sparkfun.com or www.adafruit.com for header pins.

Also, you are missing one of your i2c connections. You need both clock and data. Again, find out if you have ver 1 or ver 2 and study the GPIO connector labeling; GPIO pinout changed with versions. Read the link in my previous post regarding GPIO pins as they were a lot of help.

That IRQ pin on the mpr121 needs to connect to GPIO 17 if I remember correctly. Which is actually pin 7 on my ver 1 P1 connector.

I'm concerned because you have something connected to pin 26, and I don't. But maybe you have a version 2?

So one way or another you need good electrical connection, and you need to study the GPIO pin stuff to connect both i2c lines on the right pins on the Pi cobbler.

Feel free to email me if you have more questions. I'll try to answer ASAP.
n8telyons@gmail.com
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by N8HWV » Thu May 02, 2013 3:24 am
Connector P1 pin3 is i2c data, and P1 pin 5 is i2c clock, on both ver from what I can tell.

GPIO 4 is on P1 pin7, not to be confused with GPIO 7 which is on P1 pin 26. Connect that IRQ on the mpr121 to P1 pin 7 not 26.

Double check everything I just wrote by reading the GPIO link in my previous post. Do that and it might even work without the soldered pin headers. If not, try changing the bus address from 0 to 1, or vid versa, in the mpr121.py file.
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by dna » Fri May 31, 2013 12:43 pm
Hey there,

i am also trying to hook up the the mpr121 board via i2c on my model b pi. It is wired like that:

mpr121 --> pi
+3,3v --> Pin1 (3,3)
IRQ --> Pin7 (GPIO4)
SCL --> Pin5 (SCL)
SDA --> Pin3 (SDA)
GND --> Pin6(GND)

I am able to determine the adress of the board:
Code: Select all
pi@raspberrypi ~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --                         


I additionally checked the interrupt on Pin 7 which is constanty high. And I am also able to read out the touch state:

Code: Select all
pi@raspberrypi ~ $ i2cget -y 1 0x5a
0x00


Of course nothing is touched as the chip is in standby mode which means that the electrodes are not activated. This can be seen in the Electrode Configuration register (0x5e) which is 0x00 when the board is in standby mode:
Code: Select all
pi@raspberrypi ~ $ i2cget -y 1 0x5a 0x5e
0x00


The problem is now that I am not able to write to the chip because when I try to activate the electrodes the following happens:

Code: Select all
pi@raspberrypi ~ $ i2cset -y -r 1 0x5a 0x5e 0x0c
Warning - data mismatch - wrote 0x0c, read back 0x00


What is it I am doing wrong. Are there wrong addresses, or was my soldering faulty or do I have to solder the jumpers or connect the add pin with something. I just soldered the five wires to the board as described above.

Any help is greatly appreciated.
David
Last edited by dna on Fri May 31, 2013 2:59 pm, edited 1 time in total.
Posts: 3
Joined: Fri May 31, 2013 10:09 am
by N8HWV » Fri May 31, 2013 2:32 pm
Your table is much easier to follow. Is your project working?
Posts: 7
Joined: Fri Mar 29, 2013 6:16 pm
Location: Green Bay
by dna » Fri May 31, 2013 3:40 pm
N8HWV wrote:Your table is much easier to follow. Is your project working?


as you can see: It's not! My pi somehow posted too early so I had to edit the post to add my actual problems. Maybe you can solve them?

regards,
David
Posts: 3
Joined: Fri May 31, 2013 10:09 am
by mrteach » Fri Jun 07, 2013 7:19 pm
Was just testing my mpr121 and the table shows that on mine but the beetbox program works (except for sound) makes some electric noise but no sound... button presses show up though. I'm receiving the same results on your code that you are post.
"i2cset -y -r 1 0x5a 0x5e 0x0c." Are you attempting to use the beetbox python program or try other stuff using the 'set' command

Followed your pin set up =)
dna wrote:mpr121 --> pi
+3,3v --> Pin1 (3,3)
IRQ --> Pin7 (GPIO4)
SCL --> Pin5 (SCL)
SDA --> Pin3 (SDA)
GND --> Pin6(GND)


Edit: Sound probably not working cause I don't have any sound files...
Edit#2: Yup worked when added with sound =)
Posts: 82
Joined: Sun May 26, 2013 6:49 am
by dna » Sun Jun 16, 2013 1:34 pm
Hi there,

I am somehow not able to write to any registers on the mpr121. I change the write method to something like the following:

Code: Select all
def mpr121Write(cmd ,value, adr=address):
   print "writing to chip: ", adr, " in register: ", cmd , "value: ", value
   bus.write_byte_data(adr, cmd,value)
   print "reading from chip: ", adr, " in register: ", cmd, "value: ", bus.read_byte_data(adr, cmd)
   return None



Which yields the following results when I run the setup mpr121 method taken from the beetbox git:

Code: Select all
writing to chip:  90  in register:  94 value:  0
reading from chip:  90  in register:  94 value:  255
writing to chip:  90  in register:  43 value:  1
reading from chip:  90  in register:  43 value:  255
writing to chip:  90  in register:  44 value:  1
reading from chip:  90  in register:  44 value:  255
writing to chip:  90  in register:  45 value:  0
reading from chip:  90  in register:  45 value:  255
writing to chip:  90  in register:  46 value:  0
reading from chip:  90  in register:  46 value:  255
writing to chip:  90  in register:  47 value:  1
reading from chip:  90  in register:  47 value:  255
writing to chip:  90  in register:  48 value:  1
reading from chip:  90  in register:  48 value:  255
writing to chip:  90  in register:  49 value:  255
reading from chip:  90  in register:  49 value:  255
writing to chip:  90  in register:  50 value:  2
reading from chip:  90  in register:  50 value:  255
writing to chip:  90  in register:  65 value:  15
reading from chip:  90  in register:  65 value:  255
writing to chip:  90  in register:  66 value:  10
reading from chip:  90  in register:  66 value:  255
writing to chip:  90  in register:  67 value:  15
reading from chip:  90  in register:  67 value:  255
writing to chip:  90  in register:  68 value:  10
reading from chip:  90  in register:  68 value:  255
writing to chip:  90  in register:  69 value:  15
reading from chip:  90  in register:  69 value:  255
writing to chip:  90  in register:  70 value:  10
reading from chip:  90  in register:  70 value:  255
writing to chip:  90  in register:  71 value:  15
reading from chip:  90  in register:  71 value:  255
writing to chip:  90  in register:  72 value:  10
reading from chip:  90  in register:  72 value:  255
writing to chip:  90  in register:  73 value:  15
reading from chip:  90  in register:  73 value:  255
writing to chip:  90  in register:  74 value:  10
reading from chip:  90  in register:  74 value:  255
writing to chip:  90  in register:  75 value:  15
reading from chip:  90  in register:  75 value:  255
writing to chip:  90  in register:  76 value:  10
reading from chip:  90  in register:  76 value:  255
writing to chip:  90  in register:  77 value:  15
reading from chip:  90  in register:  77 value:  255
writing to chip:  90  in register:  78 value:  10
reading from chip:  90  in register:  78 value:  255
writing to chip:  90  in register:  79 value:  15
reading from chip:  90  in register:  79 value:  255
writing to chip:  90  in register:  80 value:  10
reading from chip:  90  in register:  80 value:  255
writing to chip:  90  in register:  81 value:  15
reading from chip:  90  in register:  81 value:  255
writing to chip:  90  in register:  82 value:  10
reading from chip:  90  in register:  82 value:  255
writing to chip:  90  in register:  83 value:  15
reading from chip:  90  in register:  83 value:  255
writing to chip:  90  in register:  84 value:  10
reading from chip:  90  in register:  84 value:  255
writing to chip:  90  in register:  85 value:  15
reading from chip:  90  in register:  85 value:  255
writing to chip:  90  in register:  86 value:  10
reading from chip:  90  in register:  86 value:  255
writing to chip:  90  in register:  87 value:  15
reading from chip:  90  in register:  87 value:  255
writing to chip:  90  in register:  88 value:  10
reading from chip:  90  in register:  88 value:  255
writing to chip:  90  in register:  93 value:  4
reading from chip:  90  in register:  93 value:  255
writing to chip:  90  in register:  94 value:  12
reading from chip:  90  in register:  94 value:  0
writing to chip:  90  in register:  94 value:  12
reading from chip:  90  in register:  94 value:  0


The interrupt is always high and never switches to low again. Can somebody please confirm using my writing method that it is possible to write to the registers.

I am able to read the touch states so the chip is somehow working but not configurable:

Code: Select all
>>> bus.read_byte_data(0x5a,0)
0
>>> bus.read_byte_data(0x5a,0)
111


and for the pins bigger than eight :

Code: Select all
>>> bus.read_byte_data(0x5a,1)
255
>>> bus.read_byte_data(0x5a,1)
255
>>> bus.read_byte_data(0x5a,1)
66


regards,
David
Posts: 3
Joined: Fri May 31, 2013 10:09 am
by EtheMan02 » Sun Mar 09, 2014 10:05 pm
I am also trying to duplicate it and I really don't know what I'm doing. Can some one maybe make a video for me? ;) Thanks
Posts: 1
Joined: Sun Mar 09, 2014 10:01 pm