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
Pypilot with ST4000 autohelm
#38
(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
Reply


Messages In This Thread
Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 12:39 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-26, 02:25 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 03:53 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-26, 04:47 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-27, 12:44 AM
RE: Pypilot with ST4000 autohelm - by CapnKernel - 2020-11-27, 01:57 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 08:02 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-26, 09:08 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 08:12 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 09:08 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-26, 09:53 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 09:59 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-26, 10:23 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-26, 11:29 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-27, 11:52 AM
RE: Pypilot with ST4000 autohelm - by CapnKernel - 2020-12-01, 02:25 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-12-01, 10:24 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-27, 09:53 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-27, 10:24 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-28, 12:08 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-28, 12:10 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-28, 10:47 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-28, 04:22 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-28, 07:54 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-28, 08:28 PM
RE: Pypilot with ST4000 autohelm - by xfactor99 - 2020-11-29, 09:53 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-11-30, 05:31 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-11-30, 09:37 PM
RE: Pypilot with ST4000 autohelm - by hreuver - 2020-12-09, 06:53 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-12-01, 06:48 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-01, 10:34 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-12-01, 11:32 AM
RE: Pypilot with ST4000 autohelm - by SYWindveer - 2020-12-04, 08:05 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-05, 03:24 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-08, 12:22 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-08, 10:23 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-08, 06:51 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-09, 11:05 AM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-12-14, 06:02 PM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-14, 07:51 PM
RE: Pypilot with ST4000 autohelm - by ironman - 2020-12-15, 11:50 AM
RE: Pypilot with ST4000 autohelm - by Peter— - 2020-12-15, 01:26 PM
RE: Pypilot with ST4000 autohelm - by AndyV - 2024-02-04, 12:21 AM

Forum Jump:


Users browsing this thread: 6 Guest(s)