Its now time to build the last part of the project before it all gets put together, which is some python code and the user of a raspberry pi. The python code is to check MQTT for a topic and receive the emotion data then to play music and output a serial command depending on what it receives. We are using the pygame lib to play audio out of the 3.m jack and the mosquito lib for MQTT. Thanks to my end of year project last year i already have working pygame code that runs on a pi playing music. so all i have to do is tweak it to work via MQTT. From the same code i made i also had serial out commands going to a ardunio so that was already done.
The part we had to work on was MQTT code , we found some examples but kept falling short in getting it to work. After 7 hours we gave up using the i-DAT broker and used the built in demo broker from the lib. Which then worked much to are confusion. After talking to Sam wray he suggested we check the ports that the broker uses. The demo code didn't use ports as by default it uses a set one. We did forget that the I-dat broker uses port 80 in order to get through eduroam so after we tweaked the code to use that board we had music playing .
The part we had to work on was MQTT code , we found some examples but kept falling short in getting it to work. After 7 hours we gave up using the i-DAT broker and used the built in demo broker from the lib. Which then worked much to are confusion. After talking to Sam wray he suggested we check the ports that the broker uses. The demo code didn't use ports as by default it uses a set one. We did forget that the I-dat broker uses port 80 in order to get through eduroam so after we tweaked the code to use that board we had music playing .
We know have working python code , now i need to get it onto the pi . My first step is to change the audio output as by defult a pi outputs sound via hdmi so every time i turn on my pi i just need to input the command
amixer cset numid=3 1
the one selcts the 3.5m jack , to learn more on this visit
https://www.raspberrypi.org/documentation/configuration/audio-config.md
now audio will come through the jack , howver when i run the code with
python chair.py
when it receives the mqtt data it crashes, so i asked Sam as he does allot of audio work. After we went back through the code we released i was using .sample to load the audio. Nomrally this works however due to the size and lengths of the songs the pi dosent have enough ram to pre load them all.
so when reciving the command by telling python to then load it as a music file and then playing it solved this error.
Things i learnt:
Ram: memory does matter using an older pygame means its slower than if i used a new pi.
pygame- i learnt how to use a new part of pygame to load songs
amixer cset numid=3 1
the one selcts the 3.5m jack , to learn more on this visit
https://www.raspberrypi.org/documentation/configuration/audio-config.md
now audio will come through the jack , howver when i run the code with
python chair.py
when it receives the mqtt data it crashes, so i asked Sam as he does allot of audio work. After we went back through the code we released i was using .sample to load the audio. Nomrally this works however due to the size and lengths of the songs the pi dosent have enough ram to pre load them all.
so when reciving the command by telling python to then load it as a music file and then playing it solved this error.
Things i learnt:
Ram: memory does matter using an older pygame means its slower than if i used a new pi.
pygame- i learnt how to use a new part of pygame to load songs