Girlish joys in the interior - not a pink shelf with Internet radio and RGB lighting
It remains a couple of weeks before March 8, and if you believe the saying, the shoemaker usually remains without shoes. Similarly, Nadia, a textile designer in the interior, lived without comfortable furniture. Many people know how difficult it is to find in a compact space of a Russian apartment a shelf or bedside table that fits perfectly in size.
When we went around almost all the shops, it became clear that the easiest way to make such furniture was ourselves. You can make an individual, not only in size, but also shelf functions and save space in the room. After discussing what we would do, Nadin and I split up: she armed herself with an electric jigsaw, a screwdriver, paint, and took the remnants of plywood from the loggia. And I sat down a little later for setting up Raspberry PI and programming. ')
Who is interested in learning only about setting up Internet radio and software development, I’ll tell you about the secret of bcm2835’s stable work with the music daemon , Apache Camel and the development of the MPD component for it.
Nadine did the most difficult and painstaking part - carpentry, soldering, installation. I recommend watching the tutorial, which lasts about an hour! In reality, work for 3-4 hours.
It all starts with a model or a sketch, a square sheet of plywood 52x52cm is mapped to 2 rectangles 18x52cm. The rest ~ 15x52cm was also useful on the third shelf.
Cutting is quite simple when there is a jigsaw.
Of course, a circular saw and a linear guide would help cut the plywood faster and smoother, but this is possible only in the workshop.
Again, in the winter there are not many options for choosing the type of paint. It is difficult in the living room to air in the cold, so better odorless water-soluble paint.
Nadin tinted the paint, by eye, stirring emerald paint in a white water-emulsion base. In order not to turn into Peppa and not to splash furniture and walls, it is better to paint a foam sponge at home. If you paint with a roller or spray, then all the furniture, walls and clothing will be in paint.
Soldering LED strip is not difficult if you use a liquid flux based on rosin and apply it to the contacts before tinning with POS-61 solder. In order for the backlight to work, it is important not to confuse the polarity of the GND power supply wires, + 5V between the tapes. The contact D (IN) of the tape is supplied with a control signal from the output on the controller SP002E, labeled D. A simpler version without soldering is if you find clamping terminals for the LED tape, but you did not find it on sale in the city of 3x.
To power the backlight and speakers, Nadia used a USB speaker wire, soldering the controller to it. USB powered speakers retail at around 400r. To isolate the conductors, the heat shrinkable tube and electrical tape also went into action.
For assembling the shelves, Nadin used two options of fasteners - wood screws for fixing the corners, Raspberry and glue gun to fix the profile with the LED tape and the speakers on the shelves. When trying to hang on the wall, the corners were replaced by more durable.
LED lighting and Smart pixel RGB (WS2812B)
LED strip with RGB LED chips WS2812B for 500r retail, it took a meter. Soldering is not difficult: only three wires are used, without a clock signal. Note that this tape will not work without a controller. For power, you need any 5V 1A power supply with a USB connector. By the way, for the control signal on the tape that I had, 3.3V was enough, so it is possible to connect to the GPIO ARM controllers without a level converter.
You can control the LED strip WS2812B using the Raspberry PI GPIO but there will be problems with playing music through the built-in audio output as the same PWM SoC generator is used as for the audio port. Therefore, the option was immediately discarded, as not working for Internet radio.
It is easier to control this ribbon with the LED controller SP002E with the MK STM8 on board - for 270r in Russian retail. It will be interesting to try to assemble a controller for this tape on from STM32 stocks with USB connection to transfer pixel values. Found several library projects on github. There is an idea to make a light music - I will write it down in my TODO list.
Install and configure Internet radio
You can consider several options for remote music playback:
Bluetooth A2DP - this is what is implemented in Bluetooth speakers, where audio compression occurs with losses. This option did not fit, as the Raspberry PI will simply turn into a “remote” speaker, and the music must be “streamed” from another device .
PulseAudio over the network - the approach is similar to A2DP, but it also requires configuring the module-native-protocol-tcp and the client.
Music Player Daemon (MPD) - ideal for offline playback of Internet radio or playlist from a local disk / NAS.
Since you need autonomous Internet radio, the choice is MPD! You can change tracks in MPD, manage playlists and volume from Android clients, such as MPD Control, as well as using desktop applications or a web interface.
As I already spoke about bcm2835 and its conflicts with GPIO functions and PWM controller - this is quite a noisy and problematic sound device. The only advantage is that it is built-in and you do not need to buy USB Audio, which is comparable in cost to Raspberry.
You must have configured mixer_type, mixer_device, mixer_control, mixer_index. Before this was done, the daemon vis when attempting to switch the track and had to restart the process.
Installation made on Raspbian under the superuser:
Run the command:
apt-get install mpd
For Raspberry PI 3 embedded audio to work, you need to add parameters to the /etc/mpd.conf configuration:
audio_output { type "alsa" name "My ALSA Device" device "hw:0,0" # optional mixer_type "software" # optional mixer_device "default" # optional mixer_control "PCM" # optional mixer_index "0" # optional } bind_to_address "192.168.1.68" port "6600" auto_update "yes"
Where "192.168.1.68" is the Raspbery address on the local network.
Controlling music from camel-mpd: developing a component for Apache Camel
Java and JVM are quite common automation platforms "Internet of things" on IoT gateways. Therefore, the development of MPD component for Camel will allow you to integrate music management into existing automation software. And of course into my favorite alarm for the fridge !
For those interested in what Apache Camel can do and where ...
"How to develop an application for automation almost not knowing how to program ." This is more about software development for IoT gateways.
The component code is available in the github repository camel-mpd and as an artifact com.github.igor-suhorukov: camel-mpd : 1.0 in the central maven repository. To work with the Music Player Daemon protocol, I chose the net.thejavashop library: javampd : 6.0.0. Judging by the committees, this library is maintained, with excellent code quality, judging by the static analysis metrics! My part of the work is the creation of a camel component, endpoint, as well as the heirs of the producer and consumer.
A few words about Camel architecture
The component is an Endpoint factory, the component has an associated protocol / scheme. Almost everything at Camel - Universal Resource Identifier. Examples: http, hdfs, smtps, irc, webcam. Now mpd !
Components are combined into routes (Route) data transformation. Route is written in one of the available domain-specific language (DSL): java, scala, groovy, spring / blueprint xml
Route can be visualized, for example using
hawt.io console.
A DSL consumer is a “from” construction at the beginning of a route. Producer in DSL is “to” construction Exchange is the message that is created and processed by the route. Contains the message body (body) and headers (headers).
You can create an apache camel component using maven:
In order for the Apache Camel context to find the component by its protocol, the component class must be specified in the src / main / resources / META-INF / services / org / apache / camel / component / mpd file class = com.github.igorsuhorukov.mpd.MpdClientComponent
The MpdClientComponent class is a factory — it creates and initializes instances of the com.github.igorsuhorukov.mpd.MpdEndpoint class. MpdEndpoint, when requested from route, creates an instance of Consumer , and its messages are passed by the component to Route. Consumer gives the route values:
volume - the current value of the volume, in the interval [0,100].
current returns information about the current song.
playlist returns a playlist as a list.
total - the total duration of the music from the playlist.
elapsed - how much time was heard.
error message, the last error that occurred.
Producer - ends Route in the context of Camel and allows you to give MPD commands:
play - start playback.
stop - stop playback.
next - select the next song.
previous - start of the previous song.
randomize - activates the transition to the next song in random order.
unrandomize - enables sequential playback of the playlist.
volume - sets the playback volume in the range from 0 to 100
song - allows you to add one or a list of songs to the playlist. And this is either the path in the file system, or Internet radio via the http protocol. The message body for this function is either a string or an org.bff.javampd.song.MPDSong object. Another option is a list of strings or a list of MPDSong objects.
While I programmed camel-mpd and edited the video, Nadine was unstoppable and made herself another chair-nightstand.
A photo
Joking that it would be good to make an analogue of a robot vacuum cleaner out of it. A new bedside table remains only to wrap with a cloth, which is in her house in prosperity and work with textiles is her strong point.
Almost happy end
An illuminated shelf was installed in the gap between the window sill and the floor, next to the radiator. Internet radio works in the background, the backlight sparkles and the cat is happy - there is more room for running on the table. Things from the table are now located on the shelf. And I still haven't thought up a gift for March 8, Nadine did almost everything herself ...