Skip to content

Commit 27932f5

Browse files
Updated feedback
Removed firmware updating Updated example image Added obstacle avoider
1 parent 9a22d59 commit 27932f5

File tree

2 files changed

+99
-13
lines changed

2 files changed

+99
-13
lines changed

content/hardware/08.edu/solution-and-kits/alvik/tutorials/setting-alvik-arduino-ide/setting-alvik-arduino-ide.md

+99-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The Arduino® Alvik robot was designed to be compatible with both C++ and MicroP
3434

3535
### Firmware Preparation
3636

37-
#### Preparing Alvik for Arduino IDE
37+
#### Preparing Alvik For Arduino IDE
3838

3939
1. Connect pin **B1** to **GND** on the Alvik board.
4040
![B1 and GND pins](assets/nano-esp32-gnd-b1.png)
@@ -43,35 +43,55 @@ The Arduino® Alvik robot was designed to be compatible with both C++ and MicroP
4343
![Select programming tool esptool](assets/EsptoolSelection.png)
4444
6. Select **Upload Using Programmer** from the **Sketch** menu.
4545
![Upload with programmer option](assets/UploadWithProgrammer.png). You can nowpPress the **Reset** button on the board to make sure it is ready for uploading.
46-
1. Open the **Bridge** example in the Arduino IDE by going to **File > Examples > 01.Basics > Blink**.
47-
![Bridge Firmware Updater](assets/bridgeFirmware.png)
48-
1. Open **STM32 Cube Programmer**
49-
2. Set the connection to **UART** mode, the **Port** to whatever port the board is connected to and **DTR** to HIGH. You can now press **Connect**.
50-
![Settings for STMCube](assets/stmCubeSetup.png)
51-
3. Go to **Erasing & Programming** mode and edit the **File path** to the firmware (this will be a .bin file) you are trying to program. You can find the latest release [here](https://github.com/arduino-libraries/Arduino_Alvik/releases/tag/1.0.1). You can now press **Start Programming**.
52-
![Programming STM Cube](assets/ProgrammingstmCube.png)
46+
1. Now we can finaly test it. Open the **Drive** example in the Arduino IDE by going to **File > Examples > Arduino_Alvik > drive**.
47+
![Upload the drive example](assets/uploadExample.png)
5348

54-
55-
1. After the firmware is programmed your board should now be ready!
49+
The Alvik should now start their motor. If no movement occurs make sure that:
50+
- Your board is **ON**
51+
- Firmware is updated (more information available in the [User Manual](https://docs.arduino.cc/tutorials/alvik/user-manual/)).
5652

5753

5854

5955
You can at any point revert back to the MicroPython programming eviroment by following the content available over at the [MicroPython installation guide](https://docs.arduino.cc/micropython/micropython-course/course/installation/).
6056

6157
## Programming Alvik
6258

63-
Let's confirm our firmware is correctly installed. For this we will create a simple sketch that prints the firmware version using the ```get_version()``` function:
59+
Now that your Alvik is correctly setup lets go over some simple sketch uploads. If this is your first time with the Arduino IDE there is information available on how to [upload sketches](https://support.arduino.cc/hc/en-us/articles/4733418441116-Upload-a-sketch-in-Arduino-IDE).
60+
61+
### Libraries
62+
63+
There are two libraries available in the library manager for use with Alvik:
64+
65+
- **Arduino_Alvik**: This is the primary library we will use in our sketches, and it contains high-level commands for controlling the "brain" of the Alvik, which is the ESP board. You can find more information and download it from [here](https://www.arduino.cc/reference/en/libraries/arduino_alvik/).
66+
67+
- **Arduino_AlvikCarrier**: This library is designed for the STM board on the device and is useful in situations where more fine control is required over commands. It allows for more complex development, especially when deeper integration with the hardware is needed. More information and the download link can be found [here](https://www.arduino.cc/reference/en/libraries/arduino_alvikcarrier/).
68+
69+
### Print Firmware Version
70+
71+
A simple but useful program if you are new to the Alvik is to understand how to get information from the onboard STM board. In this case, we are creating a simple sketch that prints the firmware version using the `get_version()` function.
6472

6573
```c++
6674
#include "Arduino_Alvik.h"
75+
```
6776

77+
Including the `Arduino_Alvik` library is essensial. The library contains all the needed predefined functions and classes that simplify the process of controlling the robot's hardware, such as motors and sensors. Without this include statement, the compiler wouldn't recognize the `Arduino_Alvik` class or its associated methods.
78+
79+
```c++
6880
Arduino_Alvik alvik;
81+
```
82+
83+
When using the Alvik livrary we declare an object of the `Arduino_Alvik` class named `alvik` in this case. All interactions with the robot will go through this `alvik` object. As with our ```alvik.drive()``` command.
6984

85+
```c++
7086
void setup() {
7187
alvik.begin();
7288
Serial.begin(115200);
7389
}
90+
```
91+
92+
In the `setup()` function, the `alvik.begin()` method initializes the Alvik robot. This will be a necessity on all sketches for the Alvik.
7493

94+
```c++
7595
void loop() {
7696

7797
uint8_t u,m,l;
@@ -86,9 +106,75 @@ void loop() {
86106
}
87107
```
88108

89-
After upload the Alvik should rotate the wheels and print the version once per second.
109+
This code continuously retrieves and prints the firmware version thanks to the ```get_version()``` every second while making the Alvik robot's wheels rotate back and forth using the ```drive()``` command.
110+
111+
112+
**Complete code:**
113+
114+
```c++
115+
#include "Arduino_Alvik.h"
116+
117+
Arduino_Alvik alvik;
118+
119+
void setup() {
120+
alvik.begin();
121+
Serial.begin(115200);
122+
}
123+
124+
void loop() {
125+
126+
uint8_t u,m,l;
127+
128+
alvik.get_version(u,m,l); // Gets the firmware version
129+
Serial.printf("%d.%d.%d\n", u, m, l);
130+
alvik.drive(10, 45);
131+
delay(1000); // Waits a second
132+
alvik.drive(10, -45);
133+
delay(1000); // Waits a second
134+
135+
}
136+
```
137+
138+
### Obstacle Avoider Example In C++
139+
140+
A more complex example can be found in the [getting started](https://docs.arduino.cc/tutorials/alvik/getting-started/) guide for the Alvik.
141+
Due to the functions having same structure and names on both MicroPython and C++ we can easily port the ```obstacle-avoider``` to C++.
142+
143+
Keeping in mind the initialization of the Alvik from the previous example we can build the example on the Arduino IDE:
144+
145+
```c++
146+
#include "Arduino_Alvik.h"
147+
#include <Arduino.h>
148+
149+
Arduino_Alvik alvik;
150+
151+
void setup() {
152+
alvik.begin();
153+
delay(5000); // Waiting for the robot to setup
154+
}
155+
156+
void loop() {
157+
float distance = 12.0;
158+
float degrees = 45.0;
159+
float speed = 10.0;
160+
161+
float distance_l, distance_cl, distance_c, distance_r, distance_cr;
162+
163+
alvik.get_distance(distance_l, distance_cl, distance_c, distance_r, distance_cr);
164+
delay(50);
165+
166+
Serial.println(distance_c);
167+
168+
if (distance_c < distance || distance_cl < distance || distance_cr < distance || distance_l < distance || distance_r < distance) {
169+
alvik.rotate(degrees);
170+
} else {
171+
alvik.drive(speed, 0.0);
172+
}
173+
}
174+
175+
```
90176

91-
You can now explore the other included examples that cover more of the Alvik's components.
177+
You can now explore the other included examples that cover more of the Alvik's components and more functions listed on our [API reference](https://docs.arduino.cc/tutorials/alvik/api-overview/).
92178

93179

94180
## More Resources (C++)

0 commit comments

Comments
 (0)