- Arduino Alvik: How to write the blinking LED code?
- How to write code for alternate Blinking LEDs with different colors in Arduino Alvik?
- How to move Arduino Alvik forward and backward using simple code?
- How to give turns to Arduino Alvik using simple code?
- Achieving control and orientation with Arduino Alvik on rotating platform
- Simple black line follower code for Arduino Alvik
- Alvik: How to use alvik.drive() function in Arduino Alvik coding
- Alvik: Detecting different colors & controlling the robot movements
- Alvik: Detecting Falling and Crashes (IMU) Corrected Code
Join Online/Offline short term course to learn advanced programming of Arduino Alvik at Vidyasagar Academy. Register now at this link.
Introduction
Arduino Alvik was launched on May 14, 2024 and there are lots of searches going on to find the correct codes for it. Arduino Alvik is a robot designed for STEM education and is intended to be a tool for hands-on learning, creativity, and critical thinking. It’s suitable for users of all ages and skill levels.
At Vidyasagar Academy we have written different interesting codes for Arduino Alvik and teaching them practically to our students. All these codes are successfully tested in our lab.
Arduino Alvik is a unique and innovative development platform, designed to expand the capabilities of the Arduino ecosystem by incorporating MicroPython as its primary programming language. Alvik focuses on offering a versatile environment for building projects that require advanced features such as real-time control, robotic automation, and sensor-based systems. This makes it particularly appealing to hobbyists, educators, and professionals alike, who want to leverage the power of both the hardware flexibility of Arduino and the ease-of-use that MicroPython provides.
With Alvik, users can easily integrate sensors, motors, LEDs, and other actuators into their projects while using high-level Pythonic constructs to write clean and efficient code. This platform retains the simplicity that Arduino is known for, but offers more advanced features typically seen in MicroPython-based environments, such as asynchronous programming, native handling of complex data structures, and fast prototyping for IoT applications.
Alvik also comes equipped with its own specialized modules and libraries that make it easier to control different hardware components like motors, sensors, and buzzers. It supports various robotic applications, including line-following robots, making it ideal for robotics enthusiasts.
How it works?
The Code for Achieving control and orientation with Arduino Alvik
This code works properly with slowly rotating platforms.
from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys
# Initialize the Alvik robot
alvik = ArduinoAlvik()
alvik.begin()
# Define a tolerance threshold for stability
gyro_threshold = 1.0 # Adjust this value as needed
# Function to adjust motors based on gyroscope data
def adjust_motors(gx, gy, gz):
if abs(gz) > gyro_threshold:
if gz > 0:
print("Rotating clockwise")
alvik.set_wheels_speed(30, -30) # Adjust the speed for clockwise rotation
else:
print("Rotating counter-clockwise")
alvik.set_wheels_speed(-30, 30) # Adjust the speed for counter-clockwise rotation
else:
print("Direction is stable, stopping motors")
alvik.set_wheels_speed(0, 0) # Stop motors when stable
while True:
try:
# Get the current accelerometer and gyroscope readings
ax, ay, az = alvik.get_accelerations()
gx, gy, gz = alvik.get_gyros()
print(f'ax: {ax}, ay: {ay}, az: {az}, gx: {gx}, gy: {gy}, gz: {gz}')
# Adjust motors based on the gyroscope data
adjust_motors(gx, gy, gz)
# Pause briefly before the next reading
sleep_ms(300)
except KeyboardInterrupt:
print('Stopping the robot')
alvik.set_wheels_speed(0, 0)
alvik.stop()
sys.exit()
Procedure to use the code in Arduino Alvik
If you are new to Arduino Alvik, the read this step-by-step procedure to create new file in Arduino Lab software and then run the code given above.