Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Nastyone
    N
    • Continue chat with Nastyone
    • Start new chat with Nastyone
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    Nastyone

    @Nastyone

    0
    Reputation
    6
    Posts
    60
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Nastyone Follow

    Posts made by Nastyone

    • RE: Help Creating a Timer

      @csierra67 said in Help Creating a Timer:

      Hi Adie,

      Two comments.
      The accuracy of any timer at the 1/100th second level is difficult to assess. You would need a reference timer and connect the start and stop signal both to this timer and to the M5stack /ESP32 based on timer
      Absence of a sytem clock. Actually there is one M5 Core 2, its RTC but it reports only seconds, minutes, hours, days.. On the other entry level Core models, there is none but you can add an RTC units that will provide the functionality
      Csierra67

      @csierra67
      Thank you again.
      I believed the RTC is just a link to an outside website for the data so not suitable for system timing references ..but probably wrong.

      Considering they promote the use of the M5Stack system for light industrial application a reliable link to the processor clock in 'ms' is vital but clearly my expectations are a little high of the Core2 having moved from learning the Arduino platform. Just for reference the below is the code I was trying to port across to the Core2 albeit it uses a relay and electro magnet for ball release where as I am now trying to move to servo release.

      Thanks again for your comments and sort of confirming the the Core 2 and me is a combination not up to much :).

      Kind regards

      Adie

      // Grove - LCD RGB Backlight - Version: Latest
      #include <Wire.h>
      #include "rgb_lcd.h"

      rgb_lcd lcd;

            const int colorR = 255;
            const int colorG = 0;
            const int colorB = 0;
      

      uint32_t btn_tStart,
      btn_tStartOld,
      sensor_tStart,
      tStart_ballRelease;

      const byte pinBtn = 2, // pin number button connected to.
      pinSensor = 3, // pin number sensor connected to.
      pinRelay = 4, // pin number relay connected to.
      debounceTimeBtn = 5; // debounce time for button. msec

      bool pinBtnState = true, // instantanious button state (noisy!)
      pinBtnStateOld = true, //
      btnStateDb = true, // debounced button state last loop
      btnStateDbOld = true, // debounced button state this loop
      btnLatch = false, //
      btnLatchOld = false, //
      sensorStateDbOld= true, // debounced sensor state last loop
      sensorStateDb = true, // debounced sensor state this loop
      ballDetected = false;

      void setup() {
      Serial.begin(9600);
      pinMode(pinBtn ,INPUT_PULLUP);
      pinMode(pinSensor ,INPUT_PULLUP);
      pinMode(pinRelay ,OUTPUT);

      //set up the LCD's number of columns and rows:
      lcd.begin(16,2);
      lcd.setRGB(colorR, colorG, colorB);
      lcd.print("Press Start");

      btn_tStartOld = 0;
      }

      void loop() {
      // read inputs and debounce.
      debounceBtn(); //debounce button signal
      sensorStateDb = digitalRead(pinSensor); //debounce not required

      // make decisions and set outputs
      doStuff();
      

      //update loop states for next round.
      btnStateDbOld = btnStateDb;
      sensorStateDbOld = sensorStateDb;
      }

      void debounceBtn() {
      pinBtnState = digitalRead(pinBtn); // get state of pin 2

      if(pinBtnStateOld != pinBtnState)
      {
      btn_tStart = millis(); // reset db timer
      pinBtnStateOld = pinBtnState; // now they are equal, won't enter
      } // here again unless pin state changes
      if (millis() - btn_tStart > debounceTimeBtn) // db timer has elapsed
      {
      btnStateDb = pinBtnState; // button state is valid
      }
      }

      void doStuff(){
      if(btnStateDb != btnStateDbOld && btnStateDb == true) // btn pressed
      {
      btnLatch = !btnLatch; // toggle latch
      digitalWrite(pinRelay,btnLatch); // set relay on/off
      if(btnLatch)
      {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Magnet On");
      //Serial.println("Magnet Energised");
      ballDetected = false; // reset latch
      }
      else
      {
      tStart_ballRelease = millis();
      lcd.setCursor(0, 0);
      lcd.print("Ball Released ");
      //Serial.println("ball released");
      }
      }

      if(sensorStateDb != sensorStateDbOld && !sensorStateDb && !btnLatch && !ballDetected) // sensor sensed.
      {
      Serial.println("msecs since ball release: "+ String(millis()-tStart_ballRelease));
      lcd.setCursor(0, 0);
      lcd.print("Ball Detected");

      lcd.setCursor(0, 1);
      lcd.print(millis()-tStart_ballRelease);
      
      ballDetected = true; // set latch
      

      }

      }

      posted in General
      N
      Nastyone
    • RE: Help Creating a Timer

      @csierra67
      Thank you for your reply.

      I ve been looking at the get tick ms function but really no idea how to use or programme it and can find no examples.

      I also figured out after hours (yeah I’m not very good) how to write an actual software timer whoop whoop! This appears to be on time as best I can tell but if I call the timer loop any quicker than 100ms it all goes Pete tong and random numbers and sequences seem to get generated. 1/10th, seconds and minutes at 100ms is the fasted stable timer I can get. I’m guessing the processor power is just not there to even run the timer that quick??

      As you say the tick function is the way to go but not something I can figure out on the Arduino is reasonably straight forward to use but I’m not finding that so here.

      Given the nature of programming and the use of timers I’m amazed there are not more or options or better examples. The absence of a system clock within the unit baffles me :)

      Thank for your help
      Adie

      posted in General
      N
      Nastyone
    • Help Creating a Timer

      Hi Guys
      OK, I ve tried my rookie best!

      I'm am trying to create a system type timer to call on a button press or possible other function but it has to measure actual TIME! My goal was actually to try and re-create something very similar to the countdown timer in the Core2 demo but obviously just running the time ever increasing until called to stop.

      I just want to run a stopwatch type clock on the screen running 1/100th's, 1/10th's and full seconds. The timer will start when a ball is released and stop when it is detected by a sensor.

      My rookie code is below and I think it is running how I expect but not linked to actual time i.e. its just counting numbers and not tied to the system or a real time clock.

      0_1695330124614_5578e788-01e0-49a5-bac9-624b48594829-image.png

      Could anybody tell me and explain what am I doing wrong please, maybe even show me what the code should look like :)

      Any help advice etc would be greatly appreciated.

      Adie

      posted in General
      N
      Nastyone
    • RE: Core 2 using servo 2 and setting M- BUS power mode in UIFLOW

      @gavin67890

      Thank you again, very much appreciated

      posted in General
      N
      Nastyone
    • RE: Core 2 using servo 2 and setting M- BUS power mode in UIFLOW

      @gavin67890
      Hi Gavin

      Sorry I am using the Core 2. The screenshot was taken on my work PC and that’s tied up with security so can’t connect the core2 to it. I’m guessing by what your hinting at my screen shot was not of the options available for the core 2 (my bad). When I get a chance I’ll hook it up to my home PC and see what options I get.

      On a side note and probably a second post eventually I’m struggling to see a simple way to access the system clock without writing a whole timer sequence?? With the Arduino it was a simplish ‘millisec’ instruction,
      Thanks again

      Adie

      posted in General
      N
      Nastyone
    • Core 2 using servo 2 and setting M- BUS power mode in UIFLOW

      Hi
      Im very new to the M5Stack system and pretty new to all things Programming and IOT. I done a little in Arduino but still taking baby steps. The move to the M5stack system was the UIFlow interface made it look easy....how wrong could I be...time will tell :)

      So my first project is using the servo2 module ( a bit overkill for one servo but hey ho) and the instruction in the documentation is - M-BUS power mode needs to be configured as input when the program is initialized

      I have searched the forum for how to carry this out in UIFlow and found the following statement - UIFlow you can use the Set bus power mode disable/enable M-Bus 5V out put block. It's under Hardware - Power, when M5Core2 is selected as device. Unfortunately my version of UIFlow (V1.12.4) doesnt appear to give me that option??
      '''0_1695027305260_09d7a3c1-f1dd-4855-9cd6-a61c667578f7-image.png
      Could anybody advise what I am doing wrong and what it is I should be doing please.

      Regards

      posted in General
      N
      Nastyone