Audio system

Long time no see! I have been busy (surprise!).
I am thinking about what the ideal audio system is for me. I want to have music in most rooms, but I don’t have much space and my budget is tight. Good thing that is it cheaper to DIY.

I want something with the same functionality as the very popular SONOS audio system, but more customizable and of course, better sounding. The plan (which is in the works) is right now:

  • Raspberry Pi 1 or 2 B for streaming with Volumio or RuneAudio software.
  • In rooms with just this audio source: HiFiBerry Amp+ or Pi-DigiAMP+ HAT (Hardware Attached on Top) which connects to the i2s on the RPi. Direct output to speaker(s).
  • In rooms with multiple audio sources: Some sort of amplifier with multiple inputs. To connect a RPi to this I can use the HiFiBerry Digi+ HAT which has toslink s/pdif output.
  • The reasons for using these i2s boards is to get better sound quality. The built in sound output on the RPi is not very good, and many users have reported issues with USB soundcards.

I need to find suitable speakers and amplifier for living room. I would like multi-room support so I can play the same music in all rooms, but I think you can do that in Volumio.. version 2 is in development, wonder when that is out?

All input welcome

Wireless working

So I had a great deal of problems with an USB wifi adapter for the Raspberry Pi that I bought on dealextreme.com. It just wasn’t stable.

Yesterday I got another USB wifi adapter, the Edimax EW-7811Un. It works great, I can recommend it. So I now had the hardware to try out prototype #2 for my R/C car.

Right now I have my Raspberry Pi powered by a USB battery pack. It runs alright but I’m not sure how much time I will get from a full charge. Then the Arduino is plugged into one USB port on the RPi, and the Edimax adapter in the other port. A 3-cell LiPo battery (mentioned before) gives power to the H-bridge and I ended up using the switch mode adapter to get 5V for the servo, as I had problems with it drawing too much current from the Arduino board and thus resetting it, sometimes just once, sometimes many times after each other.

On the RPi I have installed: nginx, uwsgi and Flask. These make my webserver. I followed one of many guides on the web to get those 3 to work together – it took hours to figure out because my linux skills are limited at best.

Here is my python code for Flask:

from flask import Flask, render_template, request, url_for
app = Flask(__name__)
import serial

def do(action):
    port = serial.Serial("/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_5533033393035131C012-if00", baudrate=9600, timeout=3.0)
    port.open()
    port.write(action)
    port.close()


@app.route("/", methods=['POST', 'GET'])
def hello():
    if request.method == 'POST':
	do(request.form['action'])
	print(request.form['action'])
	return "OK"
    else: 
    	return render_template('index.html')

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080)

I used this long path for serial control instead of simply “/dev/ttyACM0” because it would sometimes change to “/dev/ttyACM1” and then I had to change the code every time. I didn’t have that problem with this path, so I am guessing it won’t change.

This is index.html:

<!doctype html>
<head>
<title>Hello from Flask</title>

<script>
function sendAction(action)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open(“POST”, “/”,true);
xmlhttp.setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”);
xmlhttp.send(“action=” + action);
}
</script>

<link rel=”stylesheet” type=”text/css” href=”static/style.css”/>

</head>
<h1>Hello World!</h1>
<br/>

<div id=”buttons”>
<div id=”upleft”>
<input type=”image” onClick=”sendAction(‘M,50,S,-25’)” src=”static/upleft.gif” />
</div>
<div id=”upup”>
<input type=”image” onClick=”sendAction(‘M,100,S,0’)” src=”static/upup.gif” />
</div>
<div id=”upright”>
<input type=”image” onClick=”sendAction(‘M,50,S,25’)” src=”static/upright.gif” />
</div>
<div id=”up”>
<input type=”image” onClick=”sendAction(‘M,50,S,0’)” src=”static/up.gif” />
</div>
<div id=”stop”>
<input type=”image” onClick=”sendAction(‘M,0,S,0’)” src=”static/stop.gif” />
</div>
<div id=”down”>
<input type=”image” onClick=”sendAction(‘M,-50,S,0’)” src=”static/down.gif” />
</div>
<div id=”downleft”>
<input type=”image” onClick=”sendAction(‘M,-50,S,-25’)” src=”static/downleft.gif” />
</div>
<div id=”downdown”>
<input type=”image” onClick=”sendAction(‘M,-100,S,0’)” src=”static/downdown.gif” />
</div>
<div id=”downright”>
<input type=”image” onClick=”sendAction(‘M,-50,S,25’)” src=”static/downright.gif” />
</div>
</div>
<br/>

</html>

So for each button I have a div so I can control its position with css. I am using AJAX to send the request to python without having to reload the page each time I push one of the buttons.

I remapped the serial commands, so instead of full speed being “M,255,S,0” it is now “M,100,S,0”. Seems more logical.

The css file:

#buttons
{
position:relative;
text-align:center;
width:384px;
height:640px;
}

#upup{}

#up{}

#upleft
{
position:absolute;
left:0px;
top:128px;
}

#upright
{
position:absolute;
right:0px;
top:128px;
}

#stop{}

#down{}

#downdown{}

#downleft
{
position:absolute;
left:0px;
bottom:108px;
}

#downright
{
position:absolute;
right:0px;
bottom:108px;
}

As you can see, most of the buttons didn’t need to be positioned. The page now looked like this:

Capture

Pushing any of the buttons will send a POST request which will be handled by the python script and sent by serial connection to the Arduino. It worked alright until it suddenly wouldn’t run in reverse, so I sadly didn’t get to record any videos of it functioning.

IMG_20140913_135943 IMG_20140913_135950

It seems I broke my H-bridge. I don’t really know how, but I know that I won’t make another myself! I will keep it as an artifact (hmm maybe frame it? lol) and buy an IC for the project instead.

Some nice people on the subreddit /r/arduino recommended for me to add some diodes for the current to flow back from the motors to the battery, when the motors are turned off, to prevent the current from going through the transistors the wrong way. I did actually do that. So I am truly puzzled.

I guess I will also have to move away from the lunchbox as platform, and the straw and cardboard solution. Any ideas? Comments are more than welcome.

 

See ya