You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/08.edu/solution-and-kits/alvik/tutorials/api-overview/api-overview.md
+300-8
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ hardware:
13
13
## API List
14
14
15
15
To access to any of these functions you need first to initialize an instance of the class **ArduinoAlvik()**.
16
-
16
+
This reference is useful for both **MicroPython** and **C++ environments** as the functions were all created to have the same form across development environments meaning your experience should be easy to carry both options.
17
17
18
18
```arduino
19
19
alvik = ArduinoAlvik()
@@ -33,7 +33,7 @@ _Returns true if robot is on_
33
33
34
34
**Outputs**
35
35
36
-
- boolean: Returns true if robot is on, false if is off.
36
+
- boolean: Returns true if robot is on, false if it is off.
37
37
38
38
### `begin`
39
39
@@ -75,7 +75,7 @@ _Returns the orientation of the IMU_
75
75
76
76
get_accelerations()
77
77
78
-
_Returns the 3-axial acceleration of the IMU_
78
+
_Returns the 3-axial acceleration values of the IMU_
79
79
80
80
**Outputs**
81
81
@@ -136,7 +136,7 @@ _Returns last acknowledgement_
136
136
137
137
**Outputs**
138
138
139
-
-**last_ack**: last acknowledgement value
139
+
-**last_ack**: last acknowledgement value.
140
140
141
141
### `get_battery_charge`
142
142
@@ -146,7 +146,7 @@ _Returns the battery SOC_
146
146
147
147
**Outputs**
148
148
149
-
-**battery_soc**: percentage of charge
149
+
-**battery_soc**: percentage of charge.
150
150
151
151
### `get_touch_any`
152
152
@@ -633,7 +633,7 @@ _Register callback when touch button RIGHT is pressed_
633
633
-**callback**: the name of the function to recall
634
634
-**args**: optional arguments of the function
635
635
636
-
## Extras
636
+
## Function Parameters
637
637
638
638
### The Distance Unit
639
639
@@ -677,6 +677,298 @@ Rotational speed unit of measurement used in the APIs:
677
677
678
678
### `"blocking" or "non blocking"`
679
679
680
-
While programming a microcontroller, the terms "blocking" means that **all the resources are used only in performing a specific action, and no other things can happen at the same time**. Usually this is used when you want to be precise or you don't want anything else that could interact with the action you are performing.
680
+
While programming a microcontroller, the term "blocking" means that **all the resources are used only in performing a specific action, and no other things can happen at the same time**. Usually this is used when you want to be precise or you don't want anything else that could interact with the action you are performing.
681
+
682
+
On the other hand, "Non blocking", means that the microcontroller is free to do other things while the action is been performed.
683
+
684
+
## Examples
685
+
These examples demonstrate practical implementations on how to use the Arduino Alvik API. Whether you're working with MicroPython or C++, these simple examples will help you understand how to implement various features in your projects, making it easy to get started with the Alvik in the language you're most comfortable with.
686
+
687
+
### Simple Color Sensing Example
688
+
689
+
This example demonstrates how to implement basic color sensing. The Alvik's color sensor reads the color of an object placed under it, and the detected color is printed to the console.
690
+
691
+
-**Reference for MicroPython**
692
+
693
+
```python
694
+
from arduino_alvik import ArduinoAlvik
695
+
from time import sleep_ms
696
+
697
+
alvik = ArduinoAlvik()
698
+
alvik.begin()
699
+
700
+
print("Alvik initialized for color sensing")
701
+
702
+
whileTrue:
703
+
color = alvik.get_color_label()
704
+
print(f"Detected color: {color}")
705
+
sleep_ms(500)
706
+
```
707
+
708
+
-**Reference for C++**
709
+
710
+
```c
711
+
#include"Arduino_Alvik.h"
712
+
713
+
Arduino_Alvik alvik;
714
+
715
+
voidsetup() {
716
+
Serial.begin(9600);
717
+
alvik.begin();
718
+
Serial.println("Alvik initialized for color sensing");
719
+
}
720
+
721
+
voidloop() {
722
+
char* color = alvik.get_color_label();
723
+
Serial.print("Detected color: ");
724
+
Serial.println(color);
725
+
delay(500);
726
+
}
727
+
```
728
+
729
+
730
+
731
+
732
+
### Simple Directional Control
733
+
734
+
This example demonstrates very basic control over the robot's movement based on directional arrow buttons. The Alvik will drive in the direction corresponding to the arrow button pressed (up, down, left, right).
735
+
736
+
-**Reference for MicroPython**
737
+
```python
738
+
from arduino_alvik import ArduinoAlvik
739
+
from time import sleep_ms
740
+
741
+
alvik = ArduinoAlvik()
742
+
alvik.begin()
743
+
744
+
print("Alvik initialized")
745
+
746
+
whileTrue:
747
+
if alvik.get_touch_up():
748
+
print("Moving Up")
749
+
alvik.drive(100, 0, linear_unit='cm/s')
750
+
sleep_ms(1000)
751
+
alvik.brake()
752
+
elif alvik.get_touch_down():
753
+
print("Moving Down")
754
+
alvik.drive(-100, 0, linear_unit='cm/s')
755
+
sleep_ms(1000)
756
+
alvik.brake()
757
+
elif alvik.get_touch_left():
758
+
print("Turning Left")
759
+
alvik.drive(0, 100, angular_unit='deg/s')
760
+
sleep_ms(1000)
761
+
alvik.brake()
762
+
elif alvik.get_touch_right():
763
+
print("Turning Right")
764
+
alvik.drive(0, -100, angular_unit='deg/s')
765
+
sleep_ms(1000)
766
+
alvik.brake()
767
+
sleep_ms(100)
768
+
769
+
```
770
+
-**Reference for C++**
771
+
772
+
```c
773
+
#include"Arduino_Alvik.h"
774
+
775
+
Arduino_Alvik alvik;
776
+
777
+
voidsetup() {
778
+
Serial.begin(9600);
779
+
alvik.begin();
780
+
Serial.println("Alvik initialized");
781
+
}
782
+
783
+
voidloop() {
784
+
if (alvik.get_touch_up()) {
785
+
Serial.println("Moving Up");
786
+
alvik.drive(100, 0, "cm/s");
787
+
delay(1000);
788
+
alvik.brake();
789
+
} else if (alvik.get_touch_down()) {
790
+
Serial.println("Moving Down");
791
+
alvik.drive(-100, 0, "cm/s");
792
+
delay(1000);
793
+
alvik.brake();
794
+
} else if (alvik.get_touch_left()) {
795
+
Serial.println("Turning Left");
796
+
alvik.drive(0, 100, "deg/s");
797
+
delay(1000);
798
+
alvik.brake();
799
+
} else if (alvik.get_touch_right()) {
800
+
Serial.println("Turning Right");
801
+
alvik.drive(0, -100, "deg/s");
802
+
delay(1000);
803
+
alvik.brake();
804
+
}
805
+
delay(100);
806
+
}
807
+
```
808
+
809
+
### Line Following
810
+
811
+
This example demonstrates how to create a simple line-following robot. The code initializes the Alvik, reads sensor data to detect the line, calculates the error from the center of the line, and adjusts the Alvik's wheel speeds to follow the line. It also uses LEDs to indicate the direction the robot is turning.
812
+
813
+
The Alvik starts when the OK `✔` button is pressed and stops when the Cancel button is pressed. The Alvik continuously reads the line sensors, calculates the error, and adjusts the wheel speeds to correct its path.
Copy file name to clipboardExpand all lines: content/hardware/08.edu/solution-and-kits/alvik/tutorials/getting-started/getting-started.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,9 @@ Now that you have played with Alvik and have seen it moving, it is time to know
29
29
30
30
### Let's Start Coding Alvik
31
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
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
+
Alternatively, on par with other Arduino products, you can also program your Alvik using Arduino IDE and C++. If this is the case you can find setup instructions over at [Setting up Alvik on Arduino IDE](../setting-alvik-arduino-ide/setting-alvik-arduino-ide.md).
33
35
34
36
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:
0 commit comments