Raspberry Pi Pico W jetzt mit Bluetooth - Teil 3 - Robot Car mit Smartphone App - AZ-Delivery

Entering new territory is always something special, even in a figurative sense of the spiritual challenge. Raspberry Pi Pico W, also with Bluetooth support since June 2023, is such a challenge. There are almost no projects with good explanations on the Internet.

Used hardware

1

Raspberry Pi Pico W With current firmware

1

Smart Robot Car Kit

old

Any kit with chassis and wheels/engines and
L298N Motor Controller Board with DC-DC-Converter 5V (part of the above Kits)

1

Breakboard, Jumper cable, battery box With 4 AA batteries

PC with Thonny, Android smartphone/tablet

Smartphone

review

After reading the following sources, I was able to first part the blog series The display of the temperature and air humidity sensor DHT20 with Bluetooth Le to my smartphone or tablet and in the second part to realize a robot car with Bluetooth remote control with a second Pico W.

https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html

https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf

https://docs.micropython.org/en/latest/library/bluetooth.html

https://github.com/micropython/micropython/tree/master/examples/bluetooth

How I would have loved to persuade Martin O’Hanlon from the Raspberry Pi Foundation, his smartphone app Bluedot for Raspberry Pi with Python (see Blog from June 6th 2022) To adapt to Micropython promptly for the Pico W, but unfortunately that was not possible. So I had to develop my own app to control my Robot Car with my smartphone. But how do you write an app?

Smartphone app

Blogger colleague Jürgen Grzesina has already described the procedure in detail and connected an ESP32 via the domestic WLAN to the smartphone (Link to the blog) and later also realized plant irrigation (Link to the block). But after opening the Website for with app inventor I was at a loss and I didn't want to get lost in the jungle of the many examples.

So the recommended classic "Become on App Inventor, The Official Guide .." bought and studied by Karen Lang and Selim Tezel, i.e. all examples and exercises participated. The example "Find the Gold" in Chapter 5 immediately attracted my attention. Here a ball is steered to the gold treasure by tilting the smartphone by tilting the smartphone. Wouldn't the accelerometer sensor of the smartphone be suitable as good control of my Robot Car? In a first step, I develop an app in which the movement of the ball on the screen is converted into the range of values ​​0 to 31 for the Y and X axis. The horizontal smartphone in the code system I developed means 16160 = standstill, the first two places for the y-axis (back and forth), the next two places for the x-axis (left/right). In this way, I use the largest possible area for "Signed Integer" when transmission.

In addition, two screen photos of with app inventor, once the design view and then the blocks:

And the link of my exported file Controllerball.aia,

Unfortunately there is no information about Bluetooth Le in the book. Nevertheless, the book continued and that's why I can recommend it. I have the last missing part of information via a Google research and the YouTube video of Mothunderz receive. For Bluetooth LE you have to have a so -called "Extension“Download and introduce it to his project.

The top line of the website https://mit-cml.github.io/extensions/ delivers the desired extension. Simply Bluetoothle.aix Download and then import the bottom left of the inventor's range.

Here is my first attempt at an app for the Bluetooth control of the Robot Car with Raspberry Pi Pico W, first the screen photos and then the link to download.

And here are the links for Ble_controller_robotcar_unter3.aia (File for with app inventor) and Ble_controller_robotcar_unter3.apk (Installation file for Android smartphone).

The program for the Robot Car From part 2 I had to change in one place in the main part because the data format from the smartphone app somehow has not transmitted the five -digit code as a signed integer or as a string. Therefore, I first commented on the actual engine control and only displayed the received code on the screen.

In fact, the received text, e.g. B'16160 \ X00 ', The actual code framed by other characters and could therefore not be converted directly into an integer number. The first two and the last four signs had to be removed. This happens through the line

  code = Str(code)[2:-5]     # Necessary only for smartphone app

Then the string is converted into a number, which is then broken down into the individual fragments for the travel instructions.

     def on_rx(code):  # code is what has been receiven
         code = Str(code)[2:-5] # Necessary only for smartphone app
         code = intimately(code)
         cycling = intimately(code/1000)             # Digit 1 and 2
         CX = intimately((code-1000*cycling)/10)     # Digit 3 and 4
         CB = code - 1000*cycling - 10*CX     # digit 5
         print("Cy =",cycling,"CX =",CX,"CB =",CB)       # Print code fragments
         engine(cycling,CX)       # Call Function Motor With 2 Parameters

Of course, the Micropython example program will be ble_advertising.py still needed as a module on the Pico W. Otherwise you get the line “From ble_advertising import advertising_payload " an error message.

Here the slightly opposite Part 2 Changed code for the Robot Car for Download.

After testing on the PC, the program is under the name main.py Stored on the Pico W to activate the car start function when operating with batteries. Then the Pico W on the Robot Car must be started in order to be recognized with the app when scanning.

"There is Always Room for Improvement" was always so beautiful in my professional life. With the code for the Robot Car you could use an IF query to length the code (len (code)> 5) Optionally insert the new line to enable both options for control (smartphone or second Pico W as in the second part of the blog series). And you can insert up to three buttons with the value 1, 2 and 4 as a summand for the fifth place of the code, e.g. to switch on flashing light or siren or switch back and forth between remote control and an autonomous mode of the Robot Car.


If the video is not displayed, please check the cookie settings of your browser.

Have fun with your attempts with the Raspberry Pi Pico W and Bluetooth, and try the Inventor app.

Projekte für anfängerRaspberry pi

1 Reactie

Franz W.

Franz W.

Hallo
hab mit dem MIT App Inventor auch schon einige Versuche gewagt. Jedoch mit den aktuellen Android Versionen ein Graus, da die Berechtigungen nicht passen. Schade.
Wann gibt es wieder Videos zu den Projekten?
Gruß F.W.

Laat een reactie achter

Alle opmerkingen worden voor publicatie gecontroleerd door een moderator

Aanbevolen blogberichten

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery