Wish Servo library

inakigarm

Well-Known Member
Licensed User
Longtime User
Servos are a motor type that allows for precise control of angular or linear position, velocity and acceleration (wiki);there're various types with different characteristics (torque, velocity, etc)

There're very cheap models like this one and usually used on actuators, robotic arms, etc.. (two examples)

-Servo motor and Arduino
-Make a 4-Axis Robotic Arm (great !!)

A schematic of a arduino project (the secret keypad is showed when the servo moves the wheel)

arduino.png

The library to be ported is Servo library, would be great to have this library ported to B4R
 

Cableguy

Expert
Licensed User
Longtime User
I have a bunch of them, even an 1to16 i2c mux... Fun time!!!
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Tested & works fine !! (Turning Servo clockwise and counterclockwise via Timer)

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public servo1 As Servo
    Public pinservo As Pin
    Public Timer1 As Timer
    Public angleservo As UInt
    Public upangle As Boolean
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    pinservo.Initialize (4,pinservo.MODE_OUTPUT)    'connect servo to pin 4 of Arduino
    servo1.Attach(pinservo.PinNumber)                'assign servo to device on pin servo
   
    Timer1.Initialize ("Timer1_Tick",50)            'Call Timer every second
    Timer1.Enabled=True
   
    angleservo=servo1.Read                             'initial servo angle
    upangle=True                                    'Increment angle
   
End Sub

Sub Timer1_Tick
   
    angleservo=servo1.read
       
    Select upangle                                    'Increment angle               
       
        Case True       
            If (angleservo >=0 And angleservo <180) Then
                Log ("up angle ",angleservo)
                angleservo=angleservo +1
                servo1.Write(angleservo)
            End If
           
            If angleservo=180 Then upangle=False
           
        Case False                                    'Decrement angle
           
            If angleservo <=180 And angleservo>0 Then
                Log ("down angle ",angleservo)
                angleservo=angleservo-1
                servo1.Write(angleservo)
            End If
           
            If angleservo=0 Then upangle=True
       
    End Select
   
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
TESTED OK! there seems to be an issue with the IDE when the timer value is tooo low.
I played with its value, and set it to five (5), and althou Arduino side all works fine, the IDE stops responding, and it is impossible to stop the program without exiting the IDE.
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
I will slow down the logger. Note that on my computer it doesn't affect the IDE even when it logs as fast as possible.
Yes but you have a super-computer!!
 
Top