(2024-01-24, 07:57 PM)seandepagnier Wrote: [ -> ]that isnt what I read. I think he realizes the motor controller must use the only hardware serial port on the pi and to add an additional port would need bitbanging.
You are both right:
I do plan (and have programmed) an Arduino Mega with a modified motor.ino that includes SeaTalk1 communication to the Raymarine autopilot control head St7002. I only have run it on my desk and it seems to be stable. I do not check the Seatalk bus for activity when sending data. There is a chance of missing a button press (Arduino receiving data), I’ll just have to press it again. Not a big deal. There is a chance of missing a status update (Arduino sending course, status etc), of I miss that it will be sent again quickly enough not to ‘loose connection’ with the Seatalk bus (happens when no ‘command’ is received in time by the control head). I do have a ‘check bus activity’ code piece ready but have not tested it in action.
I also got that the Pi zero has only 1 serial connection and that it is used for communication with the Arduino motor controller already.
I use an Arduino Mega because I need 4 serial ports for communication: 1 for the Pi-to-Arduino motor, 1 for sending to the SeaTalk1 bus, 1 for receiving the seatalk1 bus data (I have been working for very long on comms to Seatalk with 1 connection but there does not seem to be a working library that does both… I actually use 2 different libraries) and the last one (now used for debuging) will be for receiving the course and pilot course from the Pi to send in to the Raymarine control head.
If it indeed turns out that the Seatalk communication on the same Arduino as the motor controlling interferes with it, I can of course add an Arduino, but I will first try it with just one.
I will look at your example code and see of I can get that changed to what I want. I am not familiar with running programs as services, so I have some more Google-work to do
Thanks for your answers!!
I would suggest leaving the motor.ino as is. It uses interrupt driven dead time generation if driving mosfet h-bridge directly, so adding additional code is not really recommended. If you are using the pwm output to an external controller you have some more room for code, but I would really suggest using a separate arduino to convert the other stuff and have that talk to the raspberry pi. That way the system is more modular, and you have a working pypilot in the standard setup without compromising performance.
Okay, thanks Sean. You probably know best, so I will follow your advice.
Quick update:
As suggested, I have added a separate Arduino (for now an Arduino Mega, but can 'downgrade' to any other type that has at least 2 serial ports) for the SeaTalk handling.
I have used ironman's code to create the watchlist with the parameters I want to show. This works really well.
Instead of trying bitbanging the data from the Pi to 2nd Arduino (serial port of the Pi Zero is already used for communication with the motor Arduino), I have implemented the SMBus method to use I2C communication. This is now running, seems to be very stable and the time lag is very small allready, but I can even optimise something there. I have now a time.sleep(0.5) line in the code, but I can try how far this value can be reduced without any problems.
Upto now I run the python script through SSH, so I still need to make it running as a service. I'll fix that after optimizing the code some more, and after adding so more items in the watchlist. Then I will design and mill the final PCB for the additional Arduino and put it in an enclosure.
I am actually quite pleased that I can now controll PyPilot from the Raymarine ST7002 display. Response to button presses is quite fast, data updating speed is excellent (and can even be improved easily). I have still attached my 'normal' custom control box too, and by using optocouplers I can use either this display and buttons (in which I can also access the PyPilot setup) or the Raymarine ST7002 control head.
Thanks ironman and Sean for the help!
Is there anywhere I can find information on how to run the Python script as a service in Tinypilot? I have found some methods, but the tools used in those methods don't seem to be included in Tinypilot, and I am not familiar into Linux at all...
Are you trying to add an additional service? If so you will need to add files to /etc/sv You can find the other services there. Once you have created the files (create a new folder, add the run script, "touch down" to make it by default not start and add the log folder (with run script)) you will need to create a symlink in /service
It might be helpful to execute "sudo su" to give yourself root access. Finally, you will need to edit /opt/bootlocal.sh and start the service at the appropriate place (so it doesnt slow down booting the main autopilot) and load any additional packages needed to support it.
Once you do all that be sure to run "filetool.sh -b" before rebooting or any changes you have made to the ramdisk will be lost. Please post if you get stuck anywhere or face any issues.
Thanks again for the help!
I understand I have some reading to do, and will try to get it working after that. I will keep you posted!
Regards,
Reinier
Hi all,
it's been quite a while (serious medical issues...) but in the meantime I have nearly completed the custom NavPod for my Raymarine ST7002 control panel. However, I still cannot get my script to run as a service. After a couple of tries that ended up having a 'frozen' SD card that I could do nothing with anymore, I ask for help again.
Is there (somewhere) a 'line-to-line' description on how to change my Python script into a service that automatically stars on bootup?
Looking at the services already existing, I cannot deduct what I would have to do to get my own script working. I am by no means a Linux guy, but I would really like to get it working, given that I have already got the hardware ready and would just like to finish this last part of the software things.
Regards,
Reinier
under tinypilot it is a bit cryptic
basically you have to add the service in /etc/sv make a symlink in /sv (using ln -s) and most likely edit /opt/bootlocal.sh starting the service at the right time.
Most services are disabled by default so that they can be enabled in the correct order on boot. Once you edit bootlocal.sh you must run "filetool.sh -b" to save the changes.
One way to be sure of all of this is look at an existing service. For example "pypilot_web" If you were to execute a command such as "find / | grep pypilot_web" you should possibly have a better understanding of the require steps.
Finally you could consult the runit manual to understand the service used by tinypilot:
https://smarden.org/runit/
If you have any questions at all please post here