Announcement

Collapse
No announcement yet.

Remote pump control ideas.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Re: Remote pump control ideas.

    Originally posted by Dannyx View Post
    You mean THIS ?
    At first I thought it was some sexual innuendo or something, since that's what I got among the first results on dear Google It wasn't until I punched in "STM" in the search that the board came up
    no,
    https://stm32-base.org/boards/STM32F...lack-Pill-V2.0

    Comment


      Re: Remote pump control ideas.

      No RJ45 connector on that guy, so I guess I'd have to hack in a shield to get it online. Haven't looked into it, though the form factor is appealing - it's like a Nano, just with an STM chip on it.
      Wattevah...

      Comment


        Re: Remote pump control ideas.

        yes - a big stm chip - not like the bluepill.
        bluepill is a good step forward from AVR's, but there are some fakes around now.

        btw, you can get stm boards with standard arduino size boards with the usual headers if you have a shield already.
        just remember the i/o is 3.3v
        Last edited by stj; 10-20-2020, 04:01 AM.

        Comment


          Re: Remote pump control ideas.

          Originally posted by stj View Post
          just remember the i/o is 3.3v
          That might be an issue in more "industrial" applications where they risk getting zapped easier, but I'm sure it can be dealt with...
          Wattevah...

          Comment


            Re: Remote pump control ideas.

            Ok, here we go ! Let's DO this
            Attached Files
            Wattevah...

            Comment


              Re: Remote pump control ideas.

              NICE!!! - SEND ME ONE!

              btw, there is a web-server running on an rtos on nucleo144 you can use as a base.

              Comment


                Re: Remote pump control ideas.

                That goes slightly over my head, but speaking of which: these are much nicer packed than I expected and the packaging mentions something about them coming pre-loaded with some stuff, and it would be a shame to lose that if it CAN be used in any way for my project here. I haven't even plugged them in to see what they do, so I don't know anything about them yet.

                Like I said: since I'm pressed for time, I'll just go ahead and "sacrifice" and butcher these two to run my POS Arduino code so I can get it off the ground already, but in the future, I'll DEFINITELY want to play around with the more advanced features of these, since they look really capable and it would be a shame to waste that potential. What's funny here is that Arduino, which is a dumber version for beginners, is actually more expensive than these Nucleos ! I was going to go with two Arduino Yun for this project, but the price is nearly double, for less the performance ! ! Sure, you need to KNOW how to unlock that performance to make full use of it, but it's there if you need it...kinda like having a supercar: it can go slow for city driving, but it certainly can also go to the tracks if need be
                Wattevah...

                Comment


                  Re: Remote pump control ideas.

                  the pre-load is in the virtual-usbdrive on the stlink part.
                  or it will have a weblink.

                  it's all in the cube software anyway.

                  btw, to flash code into nucleo's you just copy your bin or hex into the virtual usbdrive and the stlink will instantly flash it to the main board over the debug interface.
                  it's disgustingly simple!!
                  Last edited by stj; 10-20-2020, 02:25 PM.

                  Comment


                    Re: Remote pump control ideas.

                    Originally posted by stj View Post
                    btw, to flash code into nucleo's you just copy your bin or hex into the virtual usbdrive and the stlink will instantly flash it to the main board over the debug interface.
                    it's disgustingly simple!!
                    I think this only works for sketches you write with Cube (or is it Eclipse....couldn't quite figure out which is which yet, since there's so many pieces of software required to get this thing going it gets confusing ). Since I'll be using the ino. file my Arduino IDE spits out, or rather "uploads", I won't be able to use this feature, at least yet, since I plan on doing it right with the next ones when I'll hopefully have more time to learn. I watched some tutorials, like I said, but I'm the kind of guy who really sucks at retaining large chunks of information all at once if I'm not actually DOING that thing, so I have to practice on my own, mess it up, fix it, break it again, fix it some more and so on....
                    Wattevah...

                    Comment


                      Re: Remote pump control ideas.

                      arduino doesnt upload the INO - ever
                      that's "c", it compiles it into binary before upload.
                      you can save that compiled version.

                      Comment


                        Re: Remote pump control ideas.

                        https://www.carminenoviello.com/2016...nucleo-f746zg/

                        thid guy is a master - he writes books on this stuff

                        and this link should be bookmarked - it's the firmware updates for the stlink section.
                        https://www.st.com/en/development-to...w-link007.html
                        Last edited by stj; 10-21-2020, 12:42 PM.

                        Comment


                          Re: Remote pump control ideas.

                          How is the power consumption of the board?
                          I'm not sure what is going on at the tank station but can't see solar power working with Ethernet, it uses a lot of current. Then just go POE if there is a cable run?

                          I did not take the plunge into STM32 family, all these ARM MCU's have 1,200+ page datasheets which seem ridiculous for one person to learn and be proficient at. For now going with ATSAMD51 boards for higher performance or ESP32.

                          Comment


                            Re: Remote pump control ideas.

                            Originally posted by redwire View Post
                            How is the power consumption of the board?
                            I'm not sure what is going on at the tank station but can't see solar power working with Ethernet, it uses a lot of current. Then just go POE if there is a cable run?
                            IIRC, the network drop comes in over fiber -- any sourced power would have to be available locally (in which case, why not let the MCU use it directly?)

                            I did not take the plunge into STM32 family, all these ARM MCU's have 1,200+ page datasheets which seem ridiculous for one person to learn and be proficient at. For now going with ATSAMD51 boards for higher performance or ESP32.
                            That's been the case for many years, now. But, you're talking about SoCs, not legacy "MCUs". Much of the information in the datasheets deals with peripherals. And, the nitty-gritty details of the processors themselves are really only of interest to people writing OSs or programming on bare metal (where you really DO need to know how your code translates into electrical activity on the busses within the device)

                            Comment


                              Re: Remote pump control ideas.

                              No idea how much power the board uses (when powered with 12v that is), since I haven't taken it out of the packaging yet The GPON will also draw some power of its own.

                              I'm still working on the code on my Arduino, since I wasn't happy with how it turned out the first time and I want to do a better job at both writing it AND implementing the whole idea. This time I WILL actually share it, since I feel more confident I won't get roasted as hard
                              I started getting the hang of it better and now understand functions, since that's always been confusing AF to me as to how to pass info back and forth between the main loop and the function and also "returns" and stuff like that. It all becomes SO easy when you understand the program runs line by line, even if extremely fast which makes it look like more things happen at once - they don't - they just feel that way, like persistence of vision...again, this is all in layman terms
                              Wattevah...

                              Comment


                                Re: Remote pump control ideas.

                                power can be reduced to nothing,
                                you can shutdown the i/o in blocks so only the core runs, and even change the clockspeed on the fly.
                                you can also stall the core and have it start on an interupt from a pin or from a built-in RTC so you can have it do something every second, every hour or every day - whatever you can think of - the RTC even has it's own power pin so you could hook it to an 18650 circuit or something.

                                Comment


                                  Re: Remote pump control ideas.

                                  Here's what I concocted It works as I expect it to work. Big shoutout to STJ for giving me this idea...sort-of

                                  There's two pieces of code: one for the hilltop tank, the other for the pump at the bottom, as previously described. The client is now at the bottom shack (the pump side). This idea allowed me to simplify the code immensely and remove A LOT of clutter.
                                  I'm sure there's stuff which can be improved (for instance the lack of comments, which I'm aware of), but remember: this is extremely basic, suitable for your average beginner.

                                  Client side:
                                  Code:
                                  #include <SPI.h>
                                  #include <Ethernet.h>
                                  
                                  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBB }; //Arduino Client MAC address
                                  
                                  // If you don't want to use DNS (and reduce your sketch size)
                                  // use the numeric IP instead of the name for the server:
                                  IPAddress testServer(10, 11, 5, 239);    // IP of the first server to poll client
                                  //IPAddress testServer2(10, 11, 5, 170);   // IP of the second server to poll
                                  //char server[] = "www.google.com";    // OR name address using DNS
                                  
                                  //If DHCP is not available, the following addresses will be used by default
                                  IPAddress ip(10, 11, 5, 170);             // The static IP address that will be used if DHCP is not available
                                  IPAddress myDns(193, 231, 242, 2);           // IP of DNS server
                                  IPAddress gateway(10, 11, 5, 1);            // IP of Default Gateway
                                  IPAddress subnet (255, 255, 255, 0);          // Subnet Mask
                                  
                                  // Initialize the Ethernet client library
                                  // with the IP address and port of the server
                                  // that you want to connect to (port 80 is default for HTTP):
                                  
                                  EthernetClient theClient;
                                  
                                  //Some variables to store different stuff
                                  
                                  
                                  const int maxFailCount = 5;
                                  const int pollInterval = 5000;
                                  unsigned long lastPoll;
                                  int failCount = 0;
                                  int getStatus = 0;
                                  bool clientConnected;
                                  bool commErr;
                                  
                                  
                                  
                                  void setup() {
                                  
                                   Serial.begin(9600); // Open serial communications and wait for port to open
                                   while (!Serial) {
                                    ; // wait for serial port to connect. Needed for native USB port only
                                   }
                                  
                                  
                                   while (Ethernet.linkStatus() == LinkOFF) {
                                    Serial.println("No link. Check ethernet cable...");
                                    delay (2000);
                                   }
                                  
                                   Serial.println("Attempting to obtain DHCP lease...");
                                  
                                   if (Ethernet.begin(mac) == 0) {
                                    Serial.print("Failed to configure Ethernet using DHCP - "); //Attempt DHCP first and return this message if failed
                                  
                                    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
                                     Serial.println("Ethernet module not found or faulty..."); // Check for Ethernet shield and stop if not found
                                     while (true) {
                                      delay(1);
                                     }
                                    }
                                  
                                  
                                    Ethernet.begin(mac, ip, myDns, gateway, subnet); // Switch back to static IP (set above) if DHCP failed
                                    Serial.print("Set static IP Address as ");
                                    Serial.println(Ethernet.localIP());       //Print static IP to serial Monitor
                                    Serial.print("Gateway set as ");
                                    Serial.println(Ethernet.gatewayIP());      //Print gateway IP to serial Monitor
                                    Serial.print("Subnet mask ");
                                    Serial.println(Ethernet.subnetMask());      //Print subnet mask to serial Monitor
                                    Serial.print("DNS Server ");
                                    Serial.println(Ethernet.dnsServerIP());
                                   }     //Print DNS Server IP to serial Monitor
                                  
                                   else {
                                    Serial.print("Obtained DHCP lease. IP is "); // Print dynamic address if DHCP was successful
                                    Serial.println(Ethernet.localIP());
                                    Serial.print("Gateway IP is ");
                                    Serial.println(Ethernet.gatewayIP());
                                    Serial.print("Subnet Mask is ");
                                    Serial.println(Ethernet.subnetMask());
                                    Serial.print("DNS Server IP is ");
                                    Serial.println(Ethernet.dnsServerIP());
                                   }
                                  
                                   delay(2000); // give the Ethernet shield a second to initialize:
                                  
                                  
                                  
                                   // You can use Ethernet.init(pin) to configure the CS pin
                                   //Ethernet.init(10); // Most Arduino shields
                                   //Ethernet.init(5);  // MKR ETH shield
                                   //Ethernet.init(0);  // Teensy 2.0
                                   //Ethernet.init(20); // Teensy++ 2.0
                                   //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
                                   //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
                                  
                                   // bitClear(DDRD, 2); // PIN 2 configured as input pin
                                   // bitSet (DDRD, 3); // PIN 3 configured as output pin
                                   // bitSet (DDRD, 4); // PIN 4 configured as output pin
                                   bitSet (DDRD, 5); // PIN 5 configured as output pin
                                   bitSet (DDRD, 6); // PIN 6 configured as output pin
                                  
                                  
                                   tone(3, 1000, 1000); //startup
                                  
                                  }
                                  
                                  void loop() {
                                  
                                   Ethernet.maintain();
                                  
                                  
                                  
                                   if (clientConnected == false)
                                   { if (theClient.connect(testServer, 23))
                                    {
                                     clientConnected = true;
                                     failCount = 0;
                                    }
                                  
                                    else {
                                     if (failCount < maxFailCount) {
                                      failCount++;
                                     }
                                     if (failCount >= maxFailCount) {
                                      commErr = true;
                                     }
                                  
                                     delay(1000);
                                    }
                                   }
                                  
                                   if (clientConnected == true)
                                   { pollServer();
                                    if (getStatus == 1)
                                    {
                                     bitSet(PORTD, 5);
                                    }
                                    else if (getStatus == 0)
                                    {
                                     bitClear(PORTD, 5);
                                    }
                                   }
                                   if (commErr == true)    //on comm failure light up indicator, low beep, stop pump
                                   { bitSet(PORTD, 6);
                                    tone(3, 200, 100);
                                    bitClear(PORTD, 5);
                                   }
                                  
                                   else {
                                    bitClear(PORTD, 6);   //turn off indicator if connection resumes
                                   }
                                  }
                                  
                                  void pollServer() {
                                  
                                   failCount = 0;    //reset fail counter on each iteration of pollServer function
                                   bool invalidResponse;
                                   do {
                                    String commandString;
                                  
                                    do {
                                     if (millis() - lastPoll >= pollInterval)
                                     { theClient.print("POLL\n");
                                      lastPoll = millis();
                                      if (failCount <= maxFailCount) {
                                       failCount++;
                                      }
                                      if (failCount > maxFailCount) {
                                       clientConnected = false;
                                       commErr = true;
                                       return;
                                      }
                                     }
                                    }
                                    while (!theClient.available());
                                  
                                    while (theClient.available())
                                    { char c = theClient.read();
                                     if (c != '\n') {
                                      commandString += c;     // Read char until linefeed, then add received char to commandString variable
                                     }
                                     else {
                                      Serial.println("SwitchStatus: " + commandString);
                                      if (commandString == "ON") {
                                       getStatus = 1; //do this if ON arrives
                                       commErr = false;
                                       tone(3, 1000, 100);
                                       return;
                                      }
                                      else {
                                       if (commandString == "OFF") {
                                        getStatus = 0; //do this if OFF arrives
                                        commErr = false;
                                        tone(3, 1000, 100);
                                        return;
                                       }
                                       else {
                                        invalidResponse = true;   //do this if something else arrives (retries polling)
                                       }
                                  
                                      }
                                     }
                                    }
                                   }
                                   while (invalidResponse == true);
                                  }
                                  Last edited by Dannyx; 10-22-2020, 06:41 AM.
                                  Wattevah...

                                  Comment


                                    Re: Remote pump control ideas.

                                    Server side code

                                    Code:
                                    //SOURCE: http://www.handsonembedded.com/arduino-ethernet-shield/
                                    
                                    #include <Ethernet.h>
                                    #include <SPI.h>
                                    
                                    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA };  // Arduino Server MAC address
                                    const int port = 23;                 // Stores the value of the local port used to listen for incoming clients
                                    
                                    //If DHCP is not available, the following addresses will be used by default
                                    IPAddress ip(10, 11, 5, 170);             // The static IP address that will be used if DHCP is not available
                                    IPAddress myDns(193, 231, 242, 2);           // IP of DNS server
                                    IPAddress gateway(10, 11, 5, 1);            // IP of Default Gateway
                                    IPAddress subnet (255, 255, 255, 0);          // Subnet Mask
                                    
                                    EthernetServer theServer(port);           // Create a sever object, name it "theServer" and have it listen on the port specified above (23)
                                    
                                    unsigned long commandTime = 0;
                                    const int debounceTime = 2000;
                                    
                                    int tankStatus;
                                    
                                    
                                    void setup() {
                                    
                                     Serial.begin(9600);  // Start serial monitor
                                    
                                     if (Ethernet.linkStatus() == LinkOFF) {
                                      Serial.println("No link. Check network cable..."); //Link status check. Stop if not connected. Note that this only works on W5500 boards and is skipped otherwise !
                                      delay (2000);
                                     }
                                    
                                     Serial.println("Attempting to obtain address by DHCP...");
                                    
                                     if (Ethernet.begin(mac) == 0) {
                                      Serial.print("Failed to configure Ethernet using DHCP - "); //Attempt DHCP first and return this message if failed
                                    
                                      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
                                       Serial.println("Ethernet module not found or faulty..."); // Check for Ethernet shield and stop if not found
                                       while (true) {
                                        delay(1);
                                       }
                                      }
                                    
                                    
                                      Ethernet.begin(mac, ip, myDns, gateway, subnet); // Switch back to static IPs (set above) if DHCP failed and print out their values
                                      Serial.print("Default IP Address is ");
                                      Serial.println(Ethernet.localIP());
                                      Serial.print("Gateway IP is ");
                                      Serial.println(Ethernet.gatewayIP());
                                      Serial.print("Subnet mask is ");
                                      Serial.println(Ethernet.subnetMask());
                                      Serial.print("DNS Server IP is ");
                                      Serial.println(Ethernet.dnsServerIP());
                                     }
                                    
                                     else {
                                      Serial.print("DHCP assigned IP is "); // Print dynamic address if DHCP was successful
                                      Serial.println(Ethernet.localIP());
                                      Serial.print("Gateway IP is ");
                                      Serial.println(Ethernet.gatewayIP());
                                      Serial.print("Subnet mask is ");
                                      Serial.println(Ethernet.subnetMask());
                                      Serial.print("DNS Server IP is ");
                                      Serial.println(Ethernet.dnsServerIP());
                                     }
                                    
                                     bitClear(DDRA, 0);  // Set Digital pin 22 on the Mega as an INPUT for "RUN"
                                     bitClear(DDRA, 1);  // Set Digital pin 22 on the Mega as an INPUT for "STOP"
                                     bitSet(DDRA, 2);  // Set Digital pin 24 on the Mega as an OUTPUT for "MCU OK" indicator
                                     bitSet(DDRB, 7);  // Set LED pin 13 on the Mega as an output for switch status
                                    
                                     delay(2000); // give the Ethernet shield a second to initialize:
                                    
                                     theServer.begin();
                                    
                                     bitSet(PORTA, 2); //status LED
                                    }
                                    
                                    void loop() {
                                    
                                     Ethernet.maintain(); //probably good to disable if DHCP is not used???
                                    
                                    
                                     while (bitRead(PINA, 0) == 1)           //tank level is low and needs filling. ON contact is active (MCU pin is HIGH due to 74HC14 inverter)
                                     {
                                      commandTime = millis();
                                      break;
                                     }
                                    
                                     while (bitRead(PINA, 0) == 1)
                                     { if (millis() - commandTime > debounceTime)
                                      { if (bitRead(PINA, 1) == 0) {
                                        bitSet(PORTB, 7); //check if the OFF contact is not stuck ON
                                        tankStatus = 1;
                                        break;
                                       }
                                       else {
                                        tankStatus = 2; //
                                        break;
                                       }
                                      }
                                     }
                                    
                                    
                                     while (bitRead(PINA, 1) == 1)            //tank level is full and pump needs to stop. OFF contact is active (MCU pin is HIGH due to 74HC14 inverter)
                                     {
                                      commandTime = millis();
                                      break;
                                     }
                                    
                                     while (bitRead(PINA, 1) == 1)
                                     { if (millis() - commandTime > debounceTime)
                                      { if (bitRead(PINA, 0) == 0) {
                                        bitClear(PORTB, 7); //check if the ON contact is not stuck ON
                                        tankStatus = 0;
                                        break;
                                       }
                                       else {
                                        tankStatus = 2;
                                        break;
                                       }
                                      }//
                                     }
                                    
                                    
                                     EthernetClient theClient = theServer.available();     //Get available client wishing to speak to server
                                    
                                     String commandString;
                                     while (theClient.available())
                                     { char c = theClient.read();
                                      if (c != '\n') {
                                       commandString += c; // Read char until linefeed, then add received char to commandString variable
                                      }
                                      else {
                                       Serial.println("Command:" + commandString);
                                       if (commandString == "POLL") {
                                        doReply();
                                       }
                                      }
                                     }
                                    }
                                    
                                    void doReply() {
                                     if (tankStatus == 1)
                                     {
                                      theServer.print("ON\n");
                                     }
                                    
                                     else if (tankStatus == 0)
                                     {
                                      theServer.print("OFF\n");
                                     }
                                    
                                     else if (tankStatus == 2)
                                     {
                                      theServer.print("ERR\n");
                                     }
                                    }
                                    Wattevah...

                                    Comment


                                      Re: Remote pump control ideas.

                                      I finally unwrapped the STMs today and had a go with the Arduino IDE. Of course, I did the blinky-LED thing first to keep it as simple as possible. Amazingly, it worked first try: I was expecting errors up the a$$, but it actually uploaded. It took FOREVER to compile though ! No doubt it takes a lot of "work" to go through all this hacky process, plus my laptop is an old POS I keep strictly for messing around on, so that didn't help either.

                                      I am unable to get the serial COM port to work, since I next tried using the DHCP Address printer sketch on it to see if it'd hook up and get an IP address, but I got no serial COM port to choose from to actually SEE if it did anything - it just stood there. Then I went to the list of COM ports and found nothing there, so I'm now struggling to find a driver, since from what I read online it CAN be done....

                                      EDIT: I finally did it. Turns out there's like two different drivers: one for the ST_LINK itself and one for the STM32 "chip"........I didn't know that and kept installing the one for the chip, but not the interface COM9 now shows up. It turns out it doesn't reset the board when I open up the serial monitor, so I have to do it manually using the reset button on the board - I was just sitting there like a dumbass wondering what the heck is going on, so I just hit reset and bang, my IP address showed up.....*OOOOOOOHHHH* I see
                                      Last edited by Dannyx; 10-23-2020, 01:23 AM.
                                      Wattevah...

                                      Comment


                                        Re: Remote pump control ideas.

                                        lol
                                        did you go to my link to check your stlink is up to date?

                                        btw, you can move a couple of jumpers on the stlink part and use it standalone to program other stm32 chips.

                                        Comment


                                          Re: Remote pump control ideas.

                                          Originally posted by stj View Post
                                          lol
                                          did you go to my link to check your stlink is up to date?
                                          No, must admit I haven't done that. Will do. I got it working still. Took some tweaking, of course, but I uploaded the code to it and it works
                                          Wattevah...

                                          Comment

                                          Working...
                                          X