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
Repair / hack STW sensor.
That is awesome! Any chance of posting your code and other things (like the design for your 3D printed case) on Github?
Sure I will do it in a bit. does anyone use freecad i could post that too as i am a poor designer. functional but not beautiful. 
 Here is the code in raw form ....
  knotmeter esp8266 devboard
  Digital input GPIO12 /D6
  Output signalK navigation.speedThroughWater m/s
  David Delorme 05/4/20
  Openplotter rpi
#include <FS.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <WiFiManager.h> // WiFi Configuration Magic

const float paddleCir = .0515; // half the cir in meters of paddle
const char * udpAddress = ""; // address of signalK server
const byte WSPD_PIN = 12; // pin of ws D6 esp8266
volatile unsigned int rotation_count; //knotmeter counter
volatile uint16_t lastperiod; // time since last reading
boolean connected = false;

WiFiUDP udp;

void ICACHE_RAM_ATTR isr_knotmeter_count();
void WiFiEvent(WiFiEvent_t event);
void read_knotmeter();
void setup()
  // Setup needed for OTA
  WiFiManager wm;
  bool res;
  res = wm.autoConnect(); // auto generated AP name from chipid
  if (!res) {
    Serial.println("Failed to connect");
  else {
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";
    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  ArduinoOTA.onEnd([]() {
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR)         Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR)   Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR)     Serial.println("End Failed");
  Serial.print("IP address: ");
  attachInterrupt(digitalPinToInterrupt(WSPD_PIN), isr_knotmeter_count, FALLING);

void loop()
  // Serial.println ("made it to main loop");

// stuff done durring windspeed Interrupts
void ICACHE_RAM_ATTR isr_knotmeter_count()
  static uint16_t lastt; // lastmills
  uint32_t t = millis();// current mills
  uint16_t period = t - lastt;
  if (period < 6) // debounce, greater then 10m/s
  lastt = t;
  lastperiod += period;

void read_knotmeter()
  uint32_t time = millis();
  static uint32_t last_time;
  uint32_t dt = time - last_time;
  if (dt >= 500) { // output every 500ms
    last_time += 500;
    uint16_t period = lastperiod;
    uint16_t count = rotation_count;
    // reset the lastperiod and counter to 0
    rotation_count = 0;
    lastperiod = 0;

    static uint16_t nospeedcount;
    static float stw = 0;
    const int nospeedtimeout = 1;
    if (count) {
      if (nospeedcount != nospeedtimeout)
        stw = paddleCir * count / period * 1000; // meters/sec
      nospeedcount = 0;
    } else {
      if (nospeedcount < nospeedtimeout)
        stw = 0;
    if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status

      char buf3 [128];
      snprintf(buf3, sizeof buf3, "{\"updates\":[{ \"$source\": \"OPwifi.Knotmeter\",\"values\":[{\"path\": \"navigation.speedThroughWater\",\"value\":\"%f\" }]}]}\n", stw);
      udp.beginPacket(udpAddress, 55562); //use openplotter wifi port
      //    Serial.println("Connected to server successful!");

    } else {
      Serial.println("Error not connected");
    // Serial.println(knots);
It is basically counting ticks when ever the magnet passes the coil? i dont know what is inside the plastic though hull, just the paddle. I did see an ac voltage but it is very low current so i ignored it...Smile as the diode mode in my meter beeped when it rotated.
There is a of old code as this was rebuilt from my windsensor code and then from esp32 to esp8266.
The hookup is simple. power into a buck converter 5v to Vin on the esp32 the sensor has a black and red wire. red is attached to d6 GPIO12  and black to gnd a small resistor is connected between D6 and gnd.

Cleaned the code up removed esp32 stuff.

On the first run you need to connect to the esp access point and configure the wifi. After that it will connect automatically. you also need a connection in the skserver see the port number in the code.

Forum Jump:

Users browsing this thread: 1 Guest(s)