B4R Question Can't find servo.h

Tim Chapman

Active Member
Licensed User
Longtime User
I put this code in my B4R IDE (from here: https://www.b4x.com/android/forum/threads/servo-motor-and-arduino.66051/):

B4R servo:
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",1000)            '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

Selected the rServo library in the libraries manager.
Downloaded servo arduino library from https://github.com/arduino-libraries/Servo.
Got servo.h file from src folder there.
I put the servo.h file in my Additional Libraries folder.
Followed the directions here:

I followed the instructions there and modified my arduino-cli.yaml file to this:
board_manager:
additional_urls: []
directories:
user: D:\Downloads\B4R\Additional Libraries

I put the servo.h file in that Additional Libraries folder.

Still getting the same error message below.
Thanks in advance for the help!

cli: compile -b arduino:avr:mega D:\DOWNLO~1\B4R\TANK11~2\Objects\src\src.ino -v --board-options cpu=atmega2560
FQBN: arduino:avr:mega
Using board 'mega' from platform in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Using core 'arduino' from platform in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Detecting libraries used...
C:\Users\Owner\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega C:\Users\Owner\AppData\Local\arduino\sketches\D4B7B86979D7479C003C39D4EA72BCCE\sketch\src.ino.cpp -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
-> candidates: [Wire@1.0]
In file included from D:\Downloads\B4R\Tank11 Trying to get servo working - Copy\Objects\src\src.ino:1:0:
D:\Downloads\B4R\Tank11 Trying to get servo working - Copy\Objects\src\B4RDefines.h:23:10: fatal error: Servo.h: No such file or directory
#include <Servo.h>
^~~~~~~~~
compilation terminated.
C:\Users\Owner\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\mega -IC:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Users\Owner\AppData\Local\arduino\sketches\D4B7B86979D7479C003C39D4EA72BCCE\sketch\src.ino.cpp -o nul
Alternatives for Servo.h: []
ResolveLibrary(Servo.h)
-> candidates: []
Error during build: exit status 1
 

hatzisn

Expert
Licensed User
Longtime User
This is not the correct way. The folder must point to the Arduino libraries folder. In my situation the path had in it UTF-8 characters and the Arduino was losing the ball. Go in the Arduino IDE and check where this libraries folder is located (it is in File > Preferences - you can open it with Ctrl+{comma}). Copy this path and put it in the Directories > User in the arduino-cli configuration. The folder you have put in the arduino-cli configuration contains only wrappers of the original libraries which are contained in the folder mentioned in Arduino IDE preferences. You might also want to open this folder to check if it contains the servo library. If it does not then download it but through the Arduino IDE and the IDE will put in the mentioned folder. If it does not work you can always move this folder in another path and point both in Arduino IDE and arduino-cli configuration the programs to this path by changing the mentioned settings in both. Also do not miss the correct formatting with the intentation of two [space] characters in every child of a parent in arduino-cli configuration.
 
Last edited:
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Edit - The libraries in Arduino IDE are saved in the folder you see in "Sketchbook location" setting.
 
Upvote 0
Solution
Top