Asked — Edited

Pimoroni Pan And Tilt HAT For Rpi 3 B+

hi

i just purchased the pan tilt hat. i know it works because i tried the python examples.

But how can i get ARC to recognize it?

I do have the ez server installed on the rpi with a camera, it connects, i tried the camera control example and the video works. i added the vertical servo, tried to set it up as D0, D1 and D2. neither will control the pan and tilt hat. i believe the pan and tilt works of of i2C but i am not certain.

information on the pan and tilt hat can be found at http://pimoroni.com/pantilthat

please help, Thank you in advance.


Related Hardware Raspberry Pi

ARC Pro

Upgrade to ARC Pro

Unleash your robot's full potential with the cutting-edge features and intuitive programming offered by Synthiam ARC Pro.

PRO
Canada
#1  

Hello @j98221,

Unfortunately, you are correct, the pan and tilt hat communicates via I2C (found the pinout here). If you are able to setup those pins as regular GPIO maybe it could work with ARC. Otherwise, you may have to write an EZ-Script with I2C commands to make it work. Writing your own I2C commands is tricky business, but not impossible.

#2  

can i execute a python script from EZ-Script?

PRO
Canada
#3  

It's theoretically possible. If you have a python script running on the Pi and it's waiting for a signal from ARC (like a high signal on GPIO7 for example) you could likely make it work. I don't have a code example for you but others here in the Synthiam community might be able to help.

#4  

i will look into executing a python script with parameters from ez-script. if anyone can help i would very much appreciate it.

PRO
USA
#5  

@J98221,

I have a python solution compatible with ARC, I'll post more details later.

What model of Raspberry PI and Linux distro do you have ?

#6  

i have model 3 b+ running the latest distro which is buster.

thanks

PRO
USA
#7  

@j98221: clone the repository on your raspberry pi home folder:

cd ~/
git clone https://github.com/ppedro74/BlueberryServer.git

edit the file to match your hat controller:

vi ~/BlueberryServer/Blueberry.Server.Python/Main.py

uncomment the line 158 (setup_i2c_PimoroniPanTiltHatServoController):

###Pimoroni Pan-Tilt HAT  https://shop.pimoroni.com/products/pan-tilt-hat
###Used to map servo ports D0..D1
setup_i2c_PimoroniPanTiltHatServoController(i2c_com)

start the server (EZB and Camera Server):

cd ~/BlueberryServer/Blueberry.Server.Python/
python3 Main.py

Then use the ARC connect to the Server (you can use the Antenna to discover  the address and port) add two servo controls D0 and D1 and test the movements.

PS: Due to limited time the instructions are minimal. I'll provide more details later.

#8  

after editing line 158 and saving the file, started EZB, then i started another terminal session and started cd ~/BlueberryServer/Blueberry.Server.Python/ python3 Main.py. i received the following error;

pi@saripi:~ $ cd ~/BlueberryServer/Blueberry.Server.Python/ pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ sudo python3 Main.py & [1] 1314 pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ 1319-root-INFO-Starting... platform=linux hostname=saripi Traceback (most recent call last): File "Main.py", line 178, in main() File "Main.py", line 139, in main setup_PyAudioPlayerController() File "Main.py", line 129, in setup_PyAudioPlayerController import PyAudioPlayerController File "/home/pi/BlueberryServer/Blueberry.Server.Python/PyAudioPlayerController.py", line 7, in import pyaudio ModuleNotFoundError: No module named 'pyaudio'

PRO
USA
#9  

you need to install the pyaudio module:

sudo apt-get install python3-pyaudio
#10  

fyi, i just tried to run both in the same terminal session, and i received the same error.

#11  

i install pyaudio, i now received the following error

pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ sudo python3 Main.py & [3] 1268 pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ 1273-root-INFO-Starting... platform=linux hostname=saripi Traceback (most recent call last): File "Main.py", line 178, in main() File "Main.py", line 139, in main setup_PyAudioPlayerController() File "Main.py", line 132, in setup_PyAudioPlayerController com.start() File "/usr/lib/python3.7/contextlib.py", line 239, in helper return _GeneratorContextManager(func, args, kwds) File "/usr/lib/python3.7/contextlib.py", line 82, in init self.gen = func(*args, **kwds) File "/home/pi/BlueberryServer/Blueberry.Server.Python/PyAudioPlayerController.py", line 82, in start start=False) File "/usr/lib/python3/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/lib/python3/dist-packages/pyaudio.py", line 441, in init self._stream = pa.open(**arguments) OSError: [Errno -9997] Invalid sample rate

#12  

my python version is 3.7.3-1

PRO
USA
#13   — Edited

There is an issue with Buster and portaudio library you will need to edit your shell script:

vi ~/.bashrc

add the following line to the end:

export PA_ALSA_PLUGHW=1

you can reboot or reload the shell (previous changes):

source ~/.bashrc

if you want audio through the audio jack:

sudo amixer cset numid=3 1
#14  

i now get the following error

pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ sudo python3 Main.py 1272-root-INFO-Starting... platform=linux hostname=saripi Traceback (most recent call last): File "Main.py", line 178, in main() File "Main.py", line 139, in main setup_PyAudioPlayerController() File "Main.py", line 132, in setup_PyAudioPlayerController com.start() File "/usr/lib/python3.7/contextlib.py", line 239, in helper return _GeneratorContextManager(func, args, kwds) File "/usr/lib/python3.7/contextlib.py", line 82, in init self.gen = func(*args, **kwds) File "/home/pi/BlueberryServer/Blueberry.Server.Python/PyAudioPlayerController.py", line 82, in start start=False) File "/usr/lib/python3/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/lib/python3/dist-packages/pyaudio.py", line 441, in init self._stream = pa.open(**arguments) OSError: [Errno -9997] Invalid sample rate pi@saripi:~/BlueberryServer/Blueberry.Server.Python $

#15  

i did make the changes as you illustrated. i also just for fun added a horiz servo. tried D0 and D1- as expected the servo did not respond. also just wanted to say thanks for your effort!

#16  

can i connect the servo directly to the rpi?

if yes which gpio pin coresponds to D0?

PRO
USA
#17   — Edited

Quote:

can i connect the servo directly to the rpi?
No, the pan and tilt works through I2C, the hat has a micro-controller (maybe a PIC) with a custom firmware that handles the I2C protocol.

Please update the code:

cd ~/BlueberryServer/Blueberry.Server.Python/
git pull

Then run the following:

python3 PimoroniPanTiltHatServoController.py

Check if the pan & tilt servos move.

#18  

yes they did move horizontilay to one side and vertically point upwards. then it stopped moving.

PRO
USA
#19  

So my code is working, should work from ARC.  Maybe you're missing something, I'll post more details in couple minutes.

#20  

i did try main.py again, but i received the same error.

PRO
USA
#21  

error ?

Quote:

OSError: [Errno -9997] Invalid sample rate
Is the above error post#14 ?

If yes is audio related you can comment line 139 on Main.py:

#setup_PyAudioPlayerController()

and let me know if it works.

#22  

no errors but nothing is happening. i added a horiz and vert servo to ARC. set horiz to D0 and vert to D1. min =1 max = 180. tried moving the servos using the control, but the servo does not respond. below is what i get when i execute main.py;

pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ sudo python3 Main.py 1124-root-INFO-Starting... platform=linux hostname=saripi 1124-DeviceI2CController-1-21-DEBUG-write: bytearray(b'\x00\x08') 1124-EZBTcpServer-DEBUG-starting up on ('', 10023) 1124-EZBTcpServer-DEBUG-waiting for a connection 1124-EZBTcpServerUdpBroadcaster-DEBUG-Starting port=4242 1124-EZBTcpServerUdpBroadcaster-DEBUG-running.... 1124-EZBTcpServerUdpBroadcaster-DEBUG-broadcaster ip4 addresses found:['192.168. 8.239'] 1124-EZBCameraUdpBroadcaster-DEBUG-Starting port=4242 1124-EZBCameraUdpBroadcaster-DEBUG-running.... 1124-EZBCameraUdpBroadcaster-DEBUG-broadcaster ip4 addresses found:['192.168.8.2 39'] 1124-FakeCameraController-DEBUG-running thread:Thread-4 1124-EZBCameraTcpServer-DEBUG-starting up on ('', 10024) 1124-EZBCameraTcpServer-DEBUG-waiting for a connection ===> Press Enter to quit... 1124-EZBTcpServer-DEBUG-waiting for a connection 1124-EZBCameraTcpServer-DEBUG-waiting for a connection

PRO
USA
#23  

I don't see a connection from ARC, I'll take some pictures to guide you.

#24  

I had tried starting ezbpi server first, when that didn't work I rebooted and tried main.py first but no good on either.

Again I appreciate your help.

PRO
USA
#25  

Check this link: https://synthiam.com/Firmware/EZB-Server-BlueBerry-Server-DBJJ5DRNAAH

I'm writing about the firmware and how to use it. Let me know if it helps.

#26  

OMG the servos are working.

but now i dont have any video anymore from the rpi camera. the port use to be 24 now its 10024

PRO
USA
#27  

Check my instructions you need to click the antenna in the camera control.

you should see the camera feed or fake image with a counter.

please recheck and let me know the results.

#28  

i see a fake image with a counter

#29  

the camera works when i start the server this way: sudo nohup mono ./EZBPi.exe. obviously the servos dont.

PRO
USA
#30   — Edited

You didnt answer my question when you change the port to 10024 do you see the camera feed or a fake image. please follow/read my instructions for version 1 of BlueBerry Server.

#31  

i do see a fake image with a counter. i selected the camera by pressing the antenna button in the camera control

#32  

pi@saripi:~/BlueberryServer/Blueberry.Server.Python $ python3 Main.py 1101-root-INFO-Starting... platform=linux hostname=saripi 1101-DeviceI2CController-1-21-DEBUG-write: bytearray(b'\x00\x08') 1101-EZBTcpServer-DEBUG-starting up on ('', 10023) 1101-EZBTcpServer-DEBUG-waiting for a connection 1101-EZBTcpServerUdpBroadcaster-DEBUG-Starting port=4242 1101-EZBTcpServerUdpBroadcaster-DEBUG-running.... 1101-EZBTcpServerUdpBroadcaster-DEBUG-broadcaster ip4 addresses found:['192.168.8.239'] 1101-EZBCameraUdpBroadcaster-DEBUG-Starting port=4242 1101-EZBCameraUdpBroadcaster-DEBUG-running.... 1101-EZBCameraUdpBroadcaster-DEBUG-broadcaster ip4 addresses found:['192.168.8.239'] 1101-FakeCameraController-DEBUG-running thread:Thread-4 1101-EZBCameraTcpServer-DEBUG-starting up on ('', 10024) 1101-EZBCameraTcpServer-DEBUG-waiting for a connection ===> Press Enter to quit...

PRO
USA
#33  

It was a dumb mistake i commented the pi camera code please open the file EZBCameraServer.py and remove the comments from line 48 to 53

#34  

thanks i will try it later this evening. i need to run an errend

PRO
USA
#35  

I have updated the code (post #33)

please pull the changes:

cd ~/BlueberryServer/Blueberry.Server.Python/
git pull
#36  

i had broken the clip for the camera ribbon cable on the rpi. i went and purchased a rpi4 with 4 gig ram and an adafruit 16 channel pwm hat. i loaded all the software from scratch. i changed the main.py to reflect the adafruit pwm hat by un commenting the appropiate line, connected the servos to 0 and 1 but it did not work. servos did not move.

i then used the pimoroni pan and tilt, connected the servos and it WORKED! i made the changes you suggested for the pi camera and that worked as well. better response time on the camera.

a problem though- when selecting servo tracking in the camera control; the servos goes crazy, then stops working. also the servos will no longer work even if you un-select servo tracking, also stopping the blueberry servo and restarting it does not return the servos. i was forced to reboot the rpi4. keep in mind when i say the servos dont work is by using the vertical and horiz servo control.

upon reboot and starting the blueberry server, the camera and servos work.

what i am trying to do is add robot functionality with my rover which is powered by a px4 flight controller. i like to add ML and object recognition. i have a simple robotic arm i have not mounted yet. the rover is actually a losi five-t 1/5 scale RC with an electric motor.

do you know of any issues with the adafruit 16 channel hat?

thanks again.

PRO
USA
#37   — Edited

Quote:

do you know of any issues with the adafruit 16 channel hat?
The issue is not the HAT but the implementation.

I've used the HAT only for PWM ports so there was no support for servos, but I finished a servo implementation.

pull the project again and uncomment the following line #172:

setup_i2c_PCA9685ServoController(i2c_com)

bear in mind the hat is a PWM controller there are some calculations using the board oscillator clock 25Mhz plus the required servo frequency 50 Hz, and the 12 bits resolution, in some cases you will need to adjust the servo timings ex:

def setup_i2c_PCA9685ServoController(i2c_com):
    import PCA9685Controller
    com = PCA9685Controller.PCA9685ServoController(i2c_com, logging.DEBUG)
    ComponentRegistry.ComponentRegistry.register_controller(com)
    for port in range(16):
        ComponentRegistry.ComponentRegistry.register_component("S"+str(port), ServoController.ServoPort(com, port, 560, 2140))
    #bear in mind pwm ports frequency is 50 hz used for servos (frequency is per controller) 
    for port in range(16):
        ComponentRegistry.ComponentRegistry.register_component("P"+str(port), PWMController.PWMPort(com, port))
    com.start()

the values 560 and 2140 work well with other servo controllers but they need some adjustment when used with this HAT. Adafruit has some python calibration scripts to help you with the min and max values.