This is the library for controlling Lemon Robots with micropython via the RaspberryPi Pico
Firstly, you must connect your Pico to your computer with the pico cable. Then you must connect the PCA9685 to your Pico. Firstly you must connect the SCL, SDA, VCC and Ground pins of the PCA9685 to your picos General Purpose Input Output(GPIO) pins. You should connect SDA to pin zero, SCL to pin one. Then you should connect VCC to pin 40 and Ground to pin 38 as seen in the image below.
Then you must connect a power source(preferably 4.5-5V) to the power pins located on the side of the PCA9685 because the pico only powers the logic gates of the PCA9685.In this case we are using a 9V power supply so to regulate it to 5 volts we will use a 5v regulator.
Lastly, you must connect servos to the PCA9685. Whilst connecting the servo the orange female pin will be connected to PWM male pin, the red female pin will be connected to the V+ male pin and the black female pin will be connected to the GND male pin.
Secondly, you must prepare the LemonLib library to perform the necessary functions needed to control your robot. First, you must create a folder named Lemon then you must open your computer’s terminal and write cd Lemon. Then, you must write git clone (library link). After completing this process you will have installed the library. Next, you must install the IDE Mu Editor. (Mu editor için gereken adımları ekle).
This library works for the Lime and Satsuma robots. To control your Lime robot, you must perform the following steps. Firstly, you must import the Lemon library with the following line :
import LemonLib
Then you must initialize your I2C channel:
i2c = I2C(0, scl=Pin(1), sda=Pin(0))
The following function from the I2C class in the machine library takes three arguments. The second and the third one initialize the set pins for the I2C channel. And the first argument sets which I2C channel the PCA9685 is. After that, you must set the I2C channel you have just created for your PCA9685 and also set your PWM frequency.
pca = PCA9685(i2c)
pca.set_pwm_freq(50)
Then you must create a while loop in order to move the fish.
while True:
for angle in range:(0, 180, 5):
pca.set_angle(0, angle)
pca.set_angle(1, angle)
print(angle)
time.sleep(0.05)
for angle in range(180, 0, -5):
pca.set_angle(0, angle)
pca.set_angle(1, angle)
print(angle)
time.sleep(0.05)
The angle in range functions make the Lime fish move from 0 to 180 and then from 180 to 0 5 degrees at a time. Whilst the pca.set_angle function sets the current angle value created in the loops to the servos on the PCA9685’s first and second channels, the print(angle) function shows you the current angle value which is created by the for loops. Also the time.sleep(0.05) smooths out the movement of the fish by creating a small time interval between each iteration of the loop.
Secondly, to control the Satsuma robot. To control your Satsuma robot, you must perform the following steps. Firstly, you must import the Lemon library with the following line :
import LemonLib
Then you must initialize your I2C channel:
i2c = I2C(0, scl=Pin(1), sda=Pin(0))
The following function from the I2C class in the machine library takes three arguments. The second and the third one initialize the set pins for the I2C channel. And the first argument sets which I2C channel the PCA9685 is. After that, you must set the I2C channel you have just created for your PCA9685 and also set your PWM frequency.
pca = PCA9685(i2c)
pca.set_pwm_freq(50)
while True:
pca.set_angle(0, 40)
pca.set_angle(1, 90)
pca.set_angle(2, 40)
pca.set_angle(3, 50)
pca.set_angle(4, 90)
time.sleep(0.5)
pca.set_angle(0, 20)
pca.set_angle(1, 110)
pca.set_angle(2, 20)
pca.set_angle(3, 90)
pca.set_angle(4, 50)
This creates the loop for the turtle to go between the set intervals for it to move according to the initial design