OpenMarine
Pypilot with ST4000 autohelm - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: Pypilot (https://forum.openmarine.net/forumdisplay.php?fid=17)
+--- Forum: General discussion (https://forum.openmarine.net/forumdisplay.php?fid=18)
+--- Thread: Pypilot with ST4000 autohelm (/showthread.php?tid=3111)

Pages: 1 2 3 4 5


RE: Pypilot with ST4000 autohelm - seandepagnier - 2020-12-01

normally /dev/ttyAMA0 is in user tty or serial or something like that

check with "ls -l /dev/ttyAMA0" and also see if the user pi is in that group with "groups" You may want to add the user pi to the group.


RE: Pypilot with ST4000 autohelm - CapnKernel - 2020-12-01

(2020-11-27, 11:52 AM)Peter— Wrote: So I’m not so sure on anything anymore. Seems that I even need at 12V signal and not a 5V as I expected..

I think holding one line at ground, and sending 5V on the other will be fine:

 https://www.electronics-notes.com/articles/connectivity/serial-data-communications/rs422-basics-tutorial.php

(2020-11-27, 11:52 AM)Peter— Wrote: Hmm, the st4000 service manual says:
NMEA+: Intermittent streams of (nominal) 12V pulses
NMEA-: 0V

Source: http://www.ganssle.com/jack/st4000.pdf

That is gold!  Can't thank you enough!  It shows that their NMEA input just goes through an optoisolator, and doesn't have any special electronics to decouple the ground/power.  And if it's good enough for the famous ST4000, it's good enough for me!

The ST4000 schematic shows a PC357 optocoupler on the NMEA input, with two 2.2kΩ resistors in series with the internal LED.  The datasheet shows Vf for the LED is typically 1.2V, and optimal current for the LED is 10mA (Fig 7).  For an input of 12V, the current will be (12-1.2)/1.1kΩ = 9.8mA, so 12V is optimum for this circuit.  At 5V input, the current is (5-1.2)/1.1kΩ = 3.45mA, which will still drive the optocoupler's LED quite nicely.  For the LED's maximum current of 50mA, that would mean a maximum voltage of 50mA * 1.1kΩ = 55V.  Looks like a lot of room for handling overvoltage scenarios.


RE: Pypilot with ST4000 autohelm - ironman - 2020-12-01

For my ST2000+, it was 4800 baud. If the cable between pi and nmea input is long it could pick up magnetic interference when starting the engine; in that case I'd suggest using shielded cable e.g. ethernet cable, and tying the shield to 0V - only on one side. Please note that the autopilot route plugin was not essential. But it seems to be a slick way to go around the corner.

Having said all that, the reality of sailing by a track is that I don't really use it that often. Clicking those waypoints together on a rolling boat can be a bit of a challenge to start with. In open water you sail straight lines. In narrow, windy creeks you cannot leave the boat alone, and with wind, waves and tide together, don't expect miracles with regard to precision. With a buoy dead ahead of your bow, you don't want to go fiddle with a waypoint.

So, still, if I were you I'd first use the USB to NMEA (RS232) cable and see if it's worth all the trouble for you.

Cheers,

-

(2020-12-01, 12:22 AM)seandepagnier Wrote: normally /dev/ttyAMA0 is in user tty or serial or something like that

check with "ls -l /dev/ttyAMA0" and also see if the user pi is in that group with "groups"  You may want to add the user pi to the group.

Yeah I did try group setting, but there was a discrepancy between what I could do at the linux prompt and what opencpn could pull off. But the latter does not allow me much debugging; and I even had to kill it a few times as it got non-responsive.


RE: Pypilot with ST4000 autohelm - ironman - 2020-12-01

(2020-12-01, 02:25 AM)CapnKernel Wrote: I think holding one line at ground, and sending 5V on the other will be fine:

 https://www.electronics-notes.com/articles/connectivity/serial-data-communications/rs422-basics-tutorial.php

Your calculations I trust, but don't mistake mark for space: "A space is represented by a line voltage level in the band between +2 and +6 volts while a mark is represented by a voltage in the range -2 to -6 volts". That's what I meant when I said inverted: with ttl, a mark is electrically encoded as a positive voltage; at rs232, a mark is negative voltage.


RE: Pypilot with ST4000 autohelm - Peter— - 2020-12-01

(2020-12-01, 06:48 AM)ironman Wrote: For my ST2000+, it was 4800 baud. If the cable between pi and nmea input is long it could pick up magnetic interference when starting the engine; in that case I'd suggest using shielded cable e.g. ethernet cable, and tying the shield to 0V - only on one side. Please note that the autopilot route plugin was not essential. But it seems to be a slick way to go around the corner.

Having said all that, the reality of sailing by a track is that I don't really use it that often. Clicking those waypoints together on a rolling boat can be a bit of a challenge to start with. In open water you sail straight lines. In narrow, windy creeks you cannot leave the boat alone, and with wind, waves and tide together, don't expect miracles with regard to precision. With a buoy dead ahead of your bow, you don't want to go fiddle with a waypoint.

So, still, if I were you I'd first use the USB to NMEA (RS232) cable and see if it's worth all the trouble for you.
I actually think I’ll have quite a lot of use for it because I do sail in complicated waters with lots of rocks, islands and other obstacles. For days with no wind or little wind I can see the advantages of this and spend my time on bbq, fishing, kids, wife etc... I’ll program an alarm based on the distance to track as a double safety barrier.

I’m going to implement the UDP solution which should be very easy and OPENCPN can send the autopilot to any udp address and port.

On the ESP32 side in the raymarine I’ll pick up the udp and print it to serial. As for the inverse signal I guess you are handling that using the 3.3V instead of ground - right?

I feel safe with the photocoupler protection, they usually have like a 7000v protection. Or does the galvanic protection of the octocoupler wear over time? I mean - it’s galvanic so why would it?

Br, Peter

By the way - now that we are on the st4000 topic, I made this remote some years ago and I absolutely love it. Instead of the IR a udp, tcp or Bluetooth can alternatively be used connecting it to your smartwatch or phone which is so enjoyable.

http://www3.sympatico.ca/ericn/

As for the PCB part you can get that manufactured for a couple of dollars

Br, Peter


RE: Pypilot with ST4000 autohelm - ironman - 2020-12-01

(2020-12-01, 10:34 AM)Peter— Wrote: As for the inverse signal I guess you are handling that using the 3.3V instead of ground - right?

You got it.

(2020-12-01, 10:34 AM)Peter— Wrote: By the way - now that we are on the st4000 topic, I made this remote some years ago and I absolutely love it. Instead of the IR a udp, tcp or Bluetooth can alternatively be used connecting it to your smartwatch or phone which is so enjoyable.

http://www3.sympatico.ca/ericn/

As for the PCB part you can get that manufactured for a couple of dollars

Br, Peter

Sweet! But if you can build that, then you can also build a pypilot ;-)

I had done something similar, btw - not wireless though https://github.com/marcobergman/remote_pilot. Your code is way better - I never bothered with checking for collisions on the seatalk bus.


RE: Pypilot with ST4000 autohelm - SYWindveer - 2020-12-04

(2020-12-01, 10:34 AM)Peter— Wrote:
(2020-12-01, 06:48 AM)ironman Wrote: For my ST2000+, it was 4800 baud. If the cable between pi and nmea input is long it could pick up magnetic interference when starting the engine; in that case I'd suggest using shielded cable e.g. ethernet cable, and tying the shield to 0V - only on one side. Please note that the autopilot route plugin was not essential. But it seems to be a slick way to go around the corner.

Having said all that, the reality of sailing by a track is that I don't really use it that often. Clicking those waypoints together on a rolling boat can be a bit of a challenge to start with. In open water you sail straight lines. In narrow, windy creeks you cannot leave the boat alone, and with wind, waves and tide together, don't expect miracles with regard to precision. With a buoy dead ahead of your bow, you don't want to go fiddle with a waypoint.

So, still, if I were you I'd first use the USB to NMEA (RS232) cable and see if it's worth all the trouble for you.
I actually think I’ll have quite a lot of use for it because I do sail in complicated waters with lots of rocks, islands and other obstacles. For days with no wind or little wind I can see the advantages of this and spend my time on bbq, fishing, kids, wife etc... I’ll program an alarm based on the distance to track as a double safety barrier.

I’m going to implement the UDP solution which should be very easy and OPENCPN can send the autopilot to any udp address and port.

On the ESP32 side in the raymarine I’ll pick up the udp and print it to serial. As for the inverse signal I guess you are handling that using the 3.3V instead of ground - right?

I feel safe with the photocoupler protection, they usually have like a 7000v protection. Or does the galvanic protection of the octocoupler wear over time? I mean - it’s galvanic so why would it?

Br, Peter

By the way - now that we are on the st4000 topic, I made this remote some years ago and I absolutely love it. Instead of the IR a udp, tcp or Bluetooth can alternatively be used connecting it to your smartwatch or phone which is so enjoyable.

http://www3.sympatico.ca/ericn/

As for the PCB part you can get that manufactured for a couple of dollars

Br, Peter

So it was you who wrote that, Peter? I have been using it with my st2000 for years.


RE: Pypilot with ST4000 autohelm - Peter— - 2020-12-05

(2020-12-04, 08:05 PM)SYWindveer Wrote:
(2020-12-01, 10:34 AM)Peter— Wrote:
(2020-12-01, 06:48 AM)ironman Wrote: For my ST2000+, it was 4800 baud. If the cable between pi and nmea input is long it could pick up magnetic interference when starting the engine; in that case I'd suggest using shielded cable e.g. ethernet cable, and tying the shield to 0V - only on one side. Please note that the autopilot route plugin was not essential. But it seems to be a slick way to go around the corner.

Having said all that, the reality of sailing by a track is that I don't really use it that often. Clicking those waypoints together on a rolling boat can be a bit of a challenge to start with. In open water you sail straight lines. In narrow, windy creeks you cannot leave the boat alone, and with wind, waves and tide together, don't expect miracles with regard to precision. With a buoy dead ahead of your bow, you don't want to go fiddle with a waypoint.

So, still, if I were you I'd first use the USB to NMEA (RS232) cable and see if it's worth all the trouble for you.
I actually think I’ll have quite a lot of use for it because I do sail in complicated waters with lots of rocks, islands and other obstacles. For days with no wind or little wind I can see the advantages of this and spend my time on bbq, fishing, kids, wife etc... I’ll program an alarm based on the distance to track as a double safety barrier.

I’m going to implement the UDP solution which should be very easy and OPENCPN can send the autopilot to any udp address and port.

On the ESP32 side in the raymarine I’ll pick up the udp and print it to serial. As for the inverse signal I guess you are handling that using the 3.3V instead of ground - right?

I feel safe with the photocoupler protection, they usually have like a 7000v protection. Or does the galvanic protection of the octocoupler wear over time? I mean - it’s galvanic so why would it?

Br, Peter

By the way - now that we are on the st4000 topic, I made this remote some years ago and I absolutely love it. Instead of the IR a udp, tcp or Bluetooth can alternatively be used connecting it to your smartwatch or phone which is so enjoyable.

http://www3.sympatico.ca/ericn/

As for the PCB part you can get that manufactured for a couple of dollars

Br, Peter

So it was you who wrote that, Peter? I have been using it with my st2000 for years.

Hi all

I was just referencing the remote and cannot take the credit for that - I thought the work was so good that I wanted to share it with all of you.

Anyways, I'm planning to install my autopilot tomorrow. I'm using an ESP32 with the +3v3 pin and the tx gpio. I have followed the advices above, but instead of sending to serial OPENCPN is sending APB to network UDP on IP 10.10.10.112 (my ESP address) and port 3001. In addition I have included OTA (over the air) because my device is located behind a staircase. With OTA I can reprogram my ESP32 at any time over wifi without having to connect the ESP32 to a USB. I can also use serial monitor over wifi. As an example, I'll need to program in a hard IP-address at some point later and I'm also planning to add autopilot wind direction control.

For power, I'm using a RC plane/helicopter UBEC set at 6V. They are incredibly efficient, safe, silent and cheap. I'm using the VIN and GND pins.

Here is my code:
Code:
/*
*
*
*/

#include "AsyncUDP.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
#define led 2 //D pin (Build-in LED for Devkit V1)

const char* host = "esp32";
const char* ssid = "******raspberry ssid*********";
const char* password = "*******raspberry password***********";

int count = 0;
int count_wifi = 0;

AsyncUDP udp;


WebServer server(80);

/*
* Login page
*/

const char* loginIndex =
"<form name='loginForm'>"
   "<table width='20%' bgcolor='A09F9F' align='center'>"
       "<tr>"
           "<td colspan=2>"
               "<center><font size=4><b>ESP32 Login Page</b></font></center>"
               "<br>"
           "</td>"
           "<br>"
           "<br>"
       "</tr>"
       "<td>Username:</td>"
       "<td><input type='text' size=25 name='userid'><br></td>"
       "</tr>"
       "<br>"
       "<br>"
       "<tr>"
           "<td>Password:</td>"
           "<td><input type='Password' size=25 name='pwd'><br></td>"
           "<br>"
           "<br>"
       "</tr>"
       "<tr>"
           "<td><input type='submit' onclick='check(this.form)' value='Login'></td>"
       "</tr>"
   "</table>"
"</form>"
"<script>"
   "function check(form)"
   "{"
   "if(form.userid.value=='admin' && form.pwd.value=='admin')"
   "{"
   "window.open('/serverIndex')"
   "}"
   "else"
   "{"
   " alert('Error Password or Username')/*displays error message*/"
   "}"
   "}"
"</script>";

/*
* Server Index Page
*/

const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
  "<input type='file' name='update'>"
       "<input type='submit' value='Update'>"
   "</form>"
"<div id='prg'>progress: 0%</div>"
"<script>"
 "$('form').submit(function(e){"
 "e.preventDefault();"
 "var form = $('#upload_form')[0];"
 "var data = new FormData(form);"
 " $.ajax({"
 "url: '/update',"
 "type: 'POST',"
 "data: data,"
 "contentType: false,"
 "processData:false,"
 "xhr: function() {"
 "var xhr = new window.XMLHttpRequest();"
 "xhr.upload.addEventListener('progress', function(evt) {"
 "if (evt.lengthComputable) {"
 "var per = evt.loaded / evt.total;"
 "$('#prg').html('progress: ' + Math.round(per*100) + '%');"
 "}"
 "}, false);"
 "return xhr;"
 "},"
 "success:function(d, s) {"
 "console.log('success!')"
"},"
"error: function (a, b, c) {"
"}"
"});"
"});"
"</script>";

/*
* setup function
*/
void setup(void) {
   pinMode(led,OUTPUT);
   Serial.begin(4800);
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid, password);
   if (WiFi.waitForConnectResult() != WL_CONNECTED) {
       Serial.println("WiFi Failed");
       while(1) {
           delay(1000);
       }
   }
   if(udp.connect(IPAddress(10,10,10,1), 3333)) {
       Serial.println("UDP connected");
       udp.onPacket([](AsyncUDPPacket packet) {
           Serial.print("UDP Packet Type: ");
           Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
           Serial.print(", From: ");
           Serial.print(packet.remoteIP());
           Serial.print(":");
           Serial.print(packet.remotePort());
           Serial.print(", To: ");
           Serial.print(packet.localIP());
           Serial.print(":");
           Serial.print(packet.localPort());
           Serial.print(", Length: ");
           Serial.print(packet.length());
           Serial.print(", Data: ");
           Serial.write(packet.data(), packet.length());
           Serial.println();
           //reply to the client
           packet.printf("Got %u bytes of data", packet.length());
       });
       //Send unicast
       udp.print("Hello Server!");
   }

 //use mdns for host name resolutio
 if (!MDNS.begin(host)) { //http://esp32.local
   Serial.println("Error setting up MDNS responder!");
   while (1) {
     delay(1000);
   }
 }
 Serial.println("mDNS responder started");
 //return index page which is stored in serverIndex
 server.on("/", HTTP_GET, []() {
   server.sendHeader("Connection", "close");
   server.send(200, "text/html", loginIndex);
 });
 server.on("/serverIndex", HTTP_GET, []() {
   server.sendHeader("Connection", "close");
   server.send(200, "text/html", serverIndex);
 });
 //handling uploading firmware file //
 server.on("/update", HTTP_POST, []() {
   server.sendHeader("Connection", "close");
   server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
   ESP.restart();
 }, []() {
   HTTPUpload& upload = server.upload();
   if (upload.status == UPLOAD_FILE_START) {
     Serial.printf("Update: %s\n", upload.filename.c_str());
     if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
       Update.printError(Serial);
     }
   } else if (upload.status == UPLOAD_FILE_WRITE) {
     // flashing firmware to ESP//
     if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
       Update.printError(Serial);
     }
   } else if (upload.status == UPLOAD_FILE_END) {
     if (Update.end(true)) { //true to set the size to the current progress
       Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
     } else {
       Update.printError(Serial);
     }
   }
 });
 server.begin();
}

/*
*
*
*
*  VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP VOID LOOP
*  
*  
*  
*  
*  
*/


void loop()
{

 server.handleClient();
 digitalWrite(led, LOW);
 delay(100);

   if (udp.listen(3001)) {
     udp.onPacket([](AsyncUDPPacket packet) {
     Serial.write(packet.data(), packet.length());
     digitalWrite(led, HIGH);  
     }
     );
   }




//  } else {
//    Serial.println("failed"); //   WiFi.reconnect(); //    ESP.restart();
//    WiFi.mode(WIFI_STA);
//    WiFi.begin(ssid, password);
//  }
}

When you install the ESP32 into the Arduino IDE library there is a ton of examples included. Have a look at the examples if you want to understand the code.

Kind Regards,
Peter


RE: Pypilot with ST4000 autohelm - Peter— - 2020-12-08

So, I tried to install my ESP32 today and it didn’t work. Raymarine told me NO DATA.

Feel free to chip in if you have any ideas of why it may not be working.

I tried the following:

- As described above, 3v3 to nmea+ and tx to nmea-
- same thing, + a 4k7 pull down resister between tx and gnd to avoid pin floating
- other code: HardwareSerial.sender(1). In void-setup I used: Sender.begin(4800, Serial8N1, 27, 14) with pin 27 as tx to nmea-. And then I used Sender.write(my nmea).

None of it worked. I assume NMEA is 8N1 at 4800 br.

Any bright ideas?

Br, Peter

I’ll check my serial outputs tomorrow and see if I can troubleshoot the problem..


RE: Pypilot with ST4000 autohelm - Peter— - 2020-12-08

@Ironman, when I ready about rs422 it seems to have thresholds on 0 and 5v, and rs232 on -3v3 and +3v3 so how can it work with the 3v3v pin and gpio. Will that not just swing the voltage between 0 and 3v3 and not meeting the thresholds for the signals?

Obviously it works as you have demonstrated it... I just don’t understand how..

Update: was a bad source. Seems rs422 just needs 200mv difference (to each side so I guess the delta must be greater than 400mv):
https://www.bb-elec.com/Learning-Center/All-White-Papers/Serial/•-Polarities-for-Differential-Pair-Signals-(RS-422.aspx

It must be my tx that is the issue. The 8N1 seems correct as well. I’ll connect the tx to serial and read the data.

Br,
Peter