The Shed

PiJuice

-

machine that waited indefinite­ly for a dialled number to start counting. Every command was represente­d by a threeciphe­r sequence, parsed when the third cipher was dialled.

The list following shows the commands available as talk by the Pi rotary when the number 111 is dialled:

Note that all the textual informatio­n, the messages, and the song track titles are defined in the two JSON files: playlist.json and comments.json.

When working as a pure state machine — no main programme running after the start-up initializa­tion — there were still cases when the programme was not able to process the pulse count correctly.

What I needed was a GPIO reading engine in Python that was able to take control of the main process of reading all the events during the dialling. I also needed a Python library interfacin­g the GPIO hardware events in a more accurate way. After trying several GPIO libraries for Python, I finally adopted the PiGPIO library (http://abyz.me.uk/ rpi/pigpio/python.html), which is perfect for solving problems like this.

Notably, this multiplatf­orm library is a C-component that can be compiled in the Windows, Mac, and Linux environmen­ts, including the Raspberry Pi Linux operating system. The advantage of the library is that it uses a ‘daemon’ — a programme that runs at a lower level than the other common processors, such as the Python interprete­r, and can read any GPIO pin status change at a high frequency. An interface available for Python makes it easy to include the features inside the applicatio­n.

Once a dialled number has been recognized as the command, the programme stops the interrupts in order to avoid any interferen­ces until the command execution has been completed.

I had to adopt this solution, including the use of the red LED as a ‘ready’ signal when the programme is able to accept a new command, because when also using the PiGPIO library I experience­d some problems when the programme started other tasks, such as activating the MP3 player, while speaking.

As a matter of fact, the audio output is played by a Linux streaming command that takes control of the system in order to avoid interrupti­ons by other tasks, which may result in a poor audio sound. The programme worked perfectly after the change was made. However, the limiting factor of the solution is that it is now not possible for the programme to accept any command while a task is in execution.

I made the command available to be called as an external process from the Python programme.

The right function ‘get_weather()’ is the Python function of the programme that processes the weather forecast informatio­n provided by the terminal command ‘weather’.

The forecast data is audio spoken, but the data generated by the command are not suitable to be spoken as it is. As shown in the example following, the function extracts the informatio­n from the generated string of the command and converts it to comprehens­ible text.

An example of the weather command forecast:

 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Australia