This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding course info to Arduino serial
(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 Smile

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...
Tinypilot runs itself as services, which are defined under /etc/sv/.

Some more information you can find at
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/ 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 " -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!


Forum Jump:

Users browsing this thread: 1 Guest(s)