Skip to content

Commit da16c47

Browse files
committed
adding programming section to the new structure
1 parent 6b9b36e commit da16c47

File tree

7 files changed

+227
-44
lines changed

7 files changed

+227
-44
lines changed

content/hardware/08.edu/solution-and-kits/alvik/tutorials/01.getting-started/getting-started.md

+227-44
Original file line numberDiff line numberDiff line change
@@ -143,76 +143,123 @@ The connectors are placed in the back of the robot, the pinout is shown in the f
143143

144144
![Connectors Pinout](assets/datasheet_connectors.png)
145145

146-
## Updating Alvik (Alvik First Use)
146+
## Coding Alvik
147147

148-
### Updating Alvik's Brain (Nano ESP32)
148+
![Alvik USB Connection](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/user-manual/assets/connecting-final.gif)
149149

150-
It may happen that you used your Nano ESP32 for other projects than Alvik, or you need to replace it. In order to make your Nano ESP32 work with Alvik, there are few steps needed:
150+
In order for Alvik to work properly three things have to be set correctly:
151151

152-
1. Install the micropython bootloader on it following [this guide](https://docs.arduino.cc/micropython/basics/board-installation/).
152+
1. The Nano ESP32 needs the [MicroPython firmware](https://labs.arduino.cc/en/labs/micropython) on it.
153+
2. The [latest libraries](https://github.com/arduino/arduino-alvik-mpy/releases) have to be placed in the Nano ESP32.
154+
3. The [latest firmware](https://github.com/arduino-libraries/Arduino_AlvikCarrier/releases) has to be uploaded to the STM32 microcontroller.
153155

154-
2. Download the Alvik micropyton libraries
156+
Alvik comes with a preinstalled version of libraries and firmware, but in case you want to upgrade it or if something happens and you mess things up, here is the guide to reinstall both libraries and firmware.
155157

156-
1. Alvik micropython libraries from the [Alvik repository](https://github.com/arduino/arduino-alvik-mpy/tree/main)
157-
2. ucPack libraries from the [ucPack repository](https://github.com/arduino/ucPack-mpy/tree/main)
158+
### MicroPython Firmware on the Nano ESP32
158159

159-
3. Unzip both of the downloaded libraries in a single "Alvik" folder, open the Arduino Lab for MicroPython, go to the "files" tab and set the path to the unzipped folder on the Arduino Lab for Micropython
160+
Download and install the [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython), if you are able to connect the Arduino Nano ESP32 it means that you're board is ready. You have to see the **CONNECTED** yellow label at the bottom.
160161

161-
![Setting the FW path on the Labs for micropython](assets/fw_path.png)
162+
![Connection Succeeded](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/user-manual/assets/connection_succeeded.png)
162163

164+
If something goes wrong it means you need to upload the MicroPython firmware on the Nano ESP32.
163165

166+
Follow [this guide](https://docs.arduino.cc/micropython/basics/board-installation/).
164167

165-
4. Make sure your Alvik is OFF, connect it to your computer and then, turn it ON
168+
### How to Upload Libraries
166169

167-
![Alvik USB Connection](assets/connecting-final.gif)
170+
You will find the latest instructions directly in the [repository](https://github.com/arduino/arduino-alvik-mpy/releases). Here are the main steps:
168171

172+
1. Prepare file
169173

174+
Download the repository and extract all the files in a specific folder that will become the main Alvik folder.
170175

171-
5. Connect your Alvik to the Arduino Labs for micropython and open the "lib"
172-
![Setting the FW path on the Labs for micropython](assets/lib_folder.png)
176+
2. Remove old files
173177

174-
6. Select the "Arduino-alvik" and move it to the "lib" folder in your Alvik.
175-
![Setting the FW path on the Labs for micropython](assets/moving_alvik_folder.png)
178+
Open **Arduino Lab for MicroPython** and **connect** Alvik. Then:
176179

177-
7. Go back to the main folder and select the "ucPack-mpy-main" folder and move it next to the arduino_alvik inside the "lib" folder in your Nano ESP32.
178-
![Setting the FW path on the Labs for micropython](assets/moving_ucPack.png)
180+
- Click on the `files` icon
179181

180-
8. Now go back to the main root of the files system on the Nano ESP32. Then in your local folder navigate to the examples folder once there, select the following files and move them to the main folder of the ESP32.
182+
- Click on a `files name` in the bottom left explorer windows.
181183

182-
1. demo.py
183-
2. hand_follower.py
184-
3. line_follower.py
185-
4. main.py
186-
5. touch_move.py
184+
- Click on the `bin` icon to delete it
187185

188-
![Setting the FW path on the Labs for micropython](assets/moving_examples.png)
186+
- Repeat for all the files, from all folders
189187

190-
With this last step, your Nano ESP32 has been set up with the Alvik out of the box experience and is ready to be used.
188+
![Delete all files](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/user-manual/assets/delete_files.png)
191189

192-
### Updating Alvik's Body (STM32)
190+
3. Install mpremote
193191

194-
1. Download the [pre-compiled firmware](https://github.com/arduino-libraries/Arduino_AlvikCarrier/releases/latest) from the [Alvik Carrier GitHub reposiitory](https://github.com/arduino-libraries/Arduino_AlvikCarrier)
192+
[mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) is a Python module needed to upload files on the Nano ESP32. The minimum suggested mpremote release is 1.22.0. Be sure to have Python installed before proceeding!
195193

196-
This step will download a "firmware_x_x_x.bin" file, save it in your Alvik folder
194+
```
195+
(venv)$ pip install mpremote
196+
```
197197

198-
2. Connect your Alvik to the Computer and to the Arduino Labs for Micropython. Then, go to the files tab and navigate to the folder where you stored the "firmware_x_x_x.bin"
199-
![Setting the FW path on the Labs for micropython](assets/firmware.png)
198+
or
200199

201-
3. Let's move now the "firmware_x_x_x.bin" to the main root.
202-
![Setting the FW path on the Labs for micropython](assets/moving_fw_bin.png)
200+
```
201+
(venv)$ python3 -m pip install mpremote
202+
```
203203

204+
Depending on how you configure Python on your machine.
204205

206+
4. Install library
205207

206-
4. Turn ON your alvik, go to the Editor tab and tun the following commands by typing them and clicking on the "Play" button
207-
```shell
208-
from arduino_alvik import update_firmware
208+
Run the following line to upload all files and download the dependencies needed to run the Arduino Alvik MicroPython library.
209209

210-
update_firmware('./firmware_1_0_0.bin')
211-
```
210+
Linux
212211

213-
![Setting the FW path on the Labs for micropython](assets/flashing_fw.png)
212+
```
213+
$ ./install.sh -p <device port>
214+
```
214215

215-
After executing these commands, there will be updates of the process on the prompt, once the process finishes, the firmware of your alvik will be updated.
216+
Windows
217+
218+
```
219+
> install.bat -p <device port>
220+
```
221+
222+
The `install.*` script will copy all the needed files into your Alvik.
223+
224+
The `<device port>` is the name of the USB port that your computer assigned to the Nano ESP32. There are several ways to find it, depending on your OS, for example:
225+
226+
- You can use the Arduino IDE to discover the port, [follow this guide to know more.](https://support.arduino.cc/hc/en-us/articles/4406856349970-Select-board-and-port-in-Arduino-IDE)
227+
- You can check it by using the Arduino Lab for MicroPython by clicking `Connect` after connecting Alvik with the USB cable.
228+
- You can check the list of the USB devices attached to your PC.
229+
230+
### How to Upload Firmware
231+
232+
1. Download the latest [pre-compiled firmware](https://github.com/arduino-libraries/Arduino_AlvikCarrier/releases/latest) and place it inside Alvik's project folder
233+
234+
2. Go into `utilities` folder and run the `flash_firmware` script:
235+
236+
237+
Linux
238+
239+
```
240+
$ ./flash_firmware.sh -p <device port> <path-to-your-firmware>
241+
```
242+
243+
Windows
244+
245+
```
246+
> flash_firmware.bat -p <device port> <path-to-your-firmware>
247+
```
248+
249+
Answer `y` to flash firmware.
250+
251+
### Test
252+
253+
There are several examples to test all the features of your Alvik placed inside the `examples` folder.
254+
255+
Open **Arduino Lab for MicroPython** and **connect** Alvik. Then:
256+
257+
1. Click on the `files` icon
258+
2. Click on the `path string` in the bottom right explorer windows.
259+
3. Click on the `file name` of the example you choose
260+
4. Click on the `play button`
261+
262+
![Test examples files](assets/test_files.png)
216263

217264
## Maintenance
218265

@@ -484,16 +531,152 @@ Alvik have two controllers
484531
485532
### Line Follower
486533
534+
## Updating Alvik
535+
536+
### Updating Alvik's Brain (Nano ESP32)
537+
538+
It may happen that you used your Nano ESP32 for other projects than Alvik, or you need to replace it. In order to make your Nano ESP32 work with Alvik, there are few steps needed:
539+
540+
1. Install the micropython bootloader on it following [this guide](https://docs.arduino.cc/micropython/basics/board-installation/).
541+
542+
2. Download the Alvik micropyton libraries
543+
544+
1. Alvik micropython libraries from the [Alvik repository](https://github.com/arduino/arduino-alvik-mpy/tree/main)
545+
2. ucPack libraries from the [ucPack repository](https://github.com/arduino/ucPack-mpy/tree/main)
546+
547+
3. Unzip both of the downloaded libraries in a single "Alvik" folder, open the Arduino Lab for MicroPython, go to the "files" tab and set the path to the unzipped folder on the Arduino Lab for Micropython
548+
549+
![Setting the FW path on the Labs for micropython](assets/fw_path.png)
550+
551+
4. Make sure your Alvik is OFF, connect it to your computer and then, turn it ON
552+
553+
![Alvik USB Connection](assets/connecting-final.gif)
554+
555+
5. Connect your Alvik to the Arduino Labs for micropython and open the "lib"
556+
![Setting the FW path on the Labs for micropython](assets/lib_folder.png)
557+
558+
6. Select the "Arduino-alvik" and move it inside the "lib" folder in your Alvik.
559+
![Setting the FW path on the Labs for micropython](assets/moving_alvik_folder.png)
560+
561+
7. Go back to the main folder and select the "ucPack-mpy-main" folder and move it next to the arduino_alvik inside the "lib" folder in your Nano ESP32.
562+
![Setting the FW path on the Labs for micropython](assets/moving_ucPack.png)
563+
564+
8. Now go back to the main root of the files system on the Nano ESP32. Then in your local folder navigate to the examples folder once there, select the following files and move them to the main folder of the ESP32.
565+
566+
1. demo.py
567+
2. hand_follower.py
568+
3. line_follower.py
569+
4. main.py
570+
5. touch_move.py
571+
572+
![Setting the FW path on the Labs for micropython](assets/moving_examples.png)
573+
574+
With this last step, your Nano ESP32 has been set up with the Alvik out of the box experience and is ready to be used.
575+
576+
### Updating Alvik's Body (STM32)
577+
578+
1. Download the [pre-compiled firmware](https://github.com/arduino-libraries/Arduino_AlvikCarrier/releases/latest) from the [Alvik Carrier GitHub reposiitory](https://github.com/arduino-libraries/Arduino_AlvikCarrier)
579+
580+
This step will download a "firmware_x_x_x.bin" file, save it in your Alvik folder
581+
582+
2. Connect your Alvik to the Computer and to the Arduino Labs for Micropython. Then, go to the files tab and navigate to the folder where you stored the "firmware_x_x_x.bin"
583+
![Setting the FW path on the Labs for micropython](assets/firmware.png)
487584
488-
## Alvik First Use
585+
3. Let's move now the "firmware_x_x_x.bin" to the main root.
586+
![Setting the FW path on the Labs for micropython](assets/moving_fw_bin.png)
489587
490-
### Update Alvik's body
588+
4. Turn ON your alvik, go to the Editor tab and tun the following commands by typing them and clicking on the "Play" button
589+
590+
```shell
591+
from arduino_alvik import update_firmware
592+
593+
update_firmware('./firmware_1_0_0.bin')
594+
```
595+
596+
![Setting the FW path on the Labs for micropython](assets/flashing_fw.png)
597+
598+
After executing these commands, there will be updates of the process on the prompt, once the process finishes, the firmware of your alvik will be updated.
491599
492-
### Update Alvik's brain
493-
- Update ESP32 Micropython Firmware
494-
- Update Alvik's Library
495600
### Hello Alvik! Your first program!
496601
602+
Alvik is intended to be programmed with MicroPyton. We recommend you to install the [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython) editor.
603+
604+
Now that all the previous steps have been set, let's see how to create custom programs for Alvik to move forward until detecting an object in front of it, Alvik will detect it, dodge it and continue on its way.
605+
606+
607+
**1. **Create an Alvik folder in your computer and set it as the path of the Arduino Lab for MicroPython IDE
608+
609+
![Adding Alvik folder path to the IDE](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/assets/alvik_folder_path.png)
610+
611+
**2. **Create a new file "obstacle_avoider.py" in your local folder
612+
613+
![Creating obstacle_avoider.py file](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/assets/creating_file.png)
614+
615+
**3. **Double click on the file to open it. Once it is opened, erase the text on it and add the following code.
616+
617+
![Adding custom code](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/assets/adding_custom_code.gif)
618+
619+
``` python
620+
from arduino_alvik import ArduinoAlvik
621+
from time import sleep_ms
622+
import sys
623+
624+
alvik = ArduinoAlvik()
625+
alvik.begin()
626+
sleep_ms(5000) #waiting for the robot to setup
627+
#robot.set_illuminator(0)
628+
distance = 10
629+
speed = 40 #rpm
630+
631+
def turning():
632+
alvik.set_wheels_speed(0,0)
633+
sleep_ms(250)
634+
alvik.set_wheels_speed(-35,-35)
635+
sleep_ms(1500)
636+
alvik.set_wheels_speed(35,-35)
637+
sleep_ms(1000)
638+
639+
while (True):
640+
641+
distance_l, distance_cl, distance_c, distance_r, distance_cr = alvik.get_distance()
642+
sleep_ms(50)
643+
print(distance_c)
644+
645+
if distance_c < distance:
646+
turning()
647+
elif distance_cl < distance:
648+
turning()
649+
elif distance_cr < distance:
650+
turning()
651+
elif distance_l < distance:
652+
turning()
653+
elif distance_r < distance:
654+
turning()
655+
else:
656+
alvik.set_wheels_speed(speed, speed)
657+
658+
```
659+
660+
**4. **Connect Alvik to your PC using the cable included in the box, under the tray.
661+
662+
![Connecting Alvik to the PC](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/assets/connecting_alvik.gif)
663+
664+
***Make sure that Alvik is OFF before connecting it to your computer.***
665+
666+
**5. **Once Alvik is connected to the PC, connect it to the Arduino Lab for MicroPython and open the _main.py_ file in the Alvik folder. Once the file is opened let's replace the `import demo` statement by `import obstacle_avoider`.
667+
668+
![Connecting Alvik to the IDE](/Users/josegardel/Documents/arduino_GH/docs-content-private/content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/assets/connecting_alvik_ide.gif)
669+
670+
*** If you want to go back to the out of the box experience where you could select between reg, green and blue programs, you only need to modify the _main.py_ again replacing the `import obstacle_avoider` statement by `import demo`***
671+
672+
**6. **The last step is to move the _obstacle_avoider.py_ file from the local repository to Alvik's memory.
673+
674+
![Moving file from local to Alvik's memory](assets/local2memory.gif)
675+
676+
You are now all set, disconnect Alvik from the computer, put some obstacles around Alvik, turn it ON and see how Alvik detects them and turns to avoid them.
677+
678+
679+
497680
498681
## Program Alvik!
499682

0 commit comments

Comments
 (0)