|
| 1 | +--- |
| 2 | +title: "Getting Started with Alvik" |
| 3 | +difficulty: beginner |
| 4 | +description: "Take your first steps with Arduino® Alvik." |
| 5 | +tags: |
| 6 | + - Robot, MicroPython, Education |
| 7 | +author: "Jose Garcia" |
| 8 | +--- |
| 9 | +## Getting Started With Alvik |
| 10 | + |
| 11 | +Arduino® Alvik is a powerful and versatile robot specifically designed for programming and STEAM education. |
| 12 | + |
| 13 | + |
| 14 | +Powered by the Arduino® Nano ESP32, Alvik offers diverse learning paths through different programming languages including MicroPython, the Arduino language, and block-based coding; enabling different possibilities to explore Robotics, IoT and Artificial Intelligence. |
| 15 | + |
| 16 | +### Unboxing Alvik |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +Your Alvik robot is equipped with three ready-to-go examples. To choose one of the examples, just turn your Alvik ON, move the switch located at the bottom right corner of the robot to the right, wait until the LEDs turn blue and use the Up and Down buttons to pick one color, then hit the "tick" confirmation button. It's that easy! |
| 21 | + |
| 22 | +- **Red Program (Touch Mode):** Use the arrows to tell your robot what to do: up and down for moving forward and backward by 10 cm, and left and right for turning 90 degrees in each of the directions. The robot will collect instructions until you press the "tick" confirmation button. Once you press it, the robot will execute all the actions in order. |
| 23 | + |
| 24 | +- **Green Program (Hand Follower):** Your robot will keep a steady 10 cm distance from your hand or any object you put in front of it. Press the "tick" confirmation button again to make the robot start following your hand. You can stop the robot at any moment by pressing the "X" cancel button. |
| 25 | + |
| 26 | +- **Blue Program (Line Follower):** Your robot will glide along a black line on a white surface. Press the "tick" confirmation button again to make the robot follow the line. You can stop the robot at any moment by pressing the "X" cancel button. **The recommended size for the "black line" to follow is between 2-3 cm wide.** |
| 27 | + |
| 28 | +Now that you have played with Alvik and have seen it moving, it is time to know more in-depth how it is built and how to program Alvik to do amazing things. |
| 29 | + |
| 30 | +### Let's Start Coding Alvik |
| 31 | + |
| 32 | +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. Follow the instructions next to the download link to install it and open the IDE |
| 33 | + |
| 34 | +Now that all the previous steps have been set, let's see how to make Alvik moving across your room while avoiding objects! Let's create custom program for Alvik that: |
| 35 | + |
| 36 | + * Move forward until detecting an object in front of it |
| 37 | + * Dodge the object by turning on |
| 38 | + * Continue on its way by moving forwards again |
| 39 | + |
| 40 | +***Alvik does not have its own parachute! Be careful avoid using Alvik on your table or it could fall over the edge!*** |
| 41 | + |
| 42 | +**1. **Create an Alvik folder in your computer and set it as the path of the Arduino Lab for MicroPython IDE. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +**2. **Create a new file "obstacle_avoider.py" in your local folder. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +**3. **Double-click on the file to open it. Once it is opened, erase the text on it and add the following code. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +``` python |
| 55 | +from arduino_alvik import ArduinoAlvik |
| 56 | +from time import sleep_ms |
| 57 | +import sys |
| 58 | + |
| 59 | +alvik = ArduinoAlvik() |
| 60 | +alvik.begin() |
| 61 | +sleep_ms(5000) # waiting for the robot to setup |
| 62 | +distance = 12 |
| 63 | +degrees = 45.00 |
| 64 | +speed = 10.00 |
| 65 | + |
| 66 | +while (True): |
| 67 | + |
| 68 | + distance_l, distance_cl, distance_c, distance_r, distance_cr = alvik.get_distance() |
| 69 | + sleep_ms(50) |
| 70 | + print(distance_c) |
| 71 | + |
| 72 | + if distance_c < distance: |
| 73 | + alvik.rotate(degrees, 'deg') |
| 74 | + elif distance_cl < distance: |
| 75 | + alvik.rotate(degrees, 'deg') |
| 76 | + elif distance_cr < distance: |
| 77 | + alvik.rotate(degrees, 'deg') |
| 78 | + elif distance_l < distance: |
| 79 | + alvik.rotate(degrees, 'deg') |
| 80 | + elif distance_r < distance: |
| 81 | + alvik.rotate(degrees, 'deg') |
| 82 | + else: |
| 83 | + alvik.drive(speed, 0.0, linear_unit='cm/s') |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +**4. **Connect Alvik to your PC using the cable included in the box, under the tray. |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +***As a good practice, to prevent the Alvik from falling off the table, turn it OFF when you are programming it.*** |
| 92 | + |
| 93 | +***For Alvik to be recognized by your computer, it must be turned OFF.*** |
| 94 | + |
| 95 | +**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 with `import obstacle_avoider`. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +***If you want to go back to the out of the box experience where you could select between red, green and blue programs, you only need to modify the _main.py_ again replacing the `import obstacle_avoider` statement by `import demo`.*** |
| 100 | + |
| 101 | +**6. **The last step is to move the _obstacle_avoider.py_ file from the local repository to Alvik's memory. |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +You are now all set, disconnect Alvik from the computer, put some obstacles around Alvik, turn it ON, and see how Alvik navigates around your room avoiding them. |
| 106 | + |
| 107 | +### Next Steps |
| 108 | + |
| 109 | +* There is a set of already built examples that will help you to better understand how Alvik works, you can download them from [this link](https://github.com/arduino/arduino-alvik-mpy/archive/refs/tags/0.2.0.zip), unzip them in your already created _alvik_ folder and you will be able to see them straight away in the Arduino Labs for MicroPython IDE. |
| 110 | +* If you want to learn more about how Alvik is built or which functions you can use to program it, visit the documentation in the [Docs space for Alvik](https://docs.arduino.cc/hardware/alvik/) and follow the respective [Alvik's User Manual](https://docs.arduino.cc/hardware/alvik/user-manual) to know more about how to build incredible projects with your robot! |
| 111 | +* If you want to follow step-by-step guided projects following an educational approach to learn MicroPython and robotics topics with Alvik, follow the [Explore Robotics in MicroPython](https://courses.arduino.cc/explore-robotics-micropython/) course. |
0 commit comments