🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    [Solved]How to use the angle sensor?

    Units
    4
    24
    79.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ajb2k3A
      ajb2k3
      last edited by

      What does your code look like?

      UIFlow, so easy an adult can learn it!
      If I don't know it, be patient!
      I've ether not learned it or am too drunk to remember it!
      Author of the WIP UIFlow Handbook!
      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

      1 Reply Last reply Reply Quote 0
      • H
        heybin
        last edited by

        hello
        try to connect sensor to 36, the PORTB, test

        K 1 Reply Last reply Reply Quote 0
        • K
          ken57093 @heybin
          last edited by ken57093

          @heybin 0_1538443658559_3594191f-351e-48e2-bb0a-3f26f0ca7af1-image.png
          Here is some different on the monitor. However the output still not controlled by the sensor.Will you have another idea? Thank you.
          update
          I had tried digitalread() for both 22 and 36. Only 22 return 0 or 1 and 36 only return 0

          1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3
            last edited by

            What device are you using and have you tuned the sensor?

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            1 Reply Last reply Reply Quote 0
            • K
              ken57093
              last edited by ken57093

              @ajb2k3
              0_1538465242232_20181002_152122.jpg
              ESP32 M5 core

              1 Reply Last reply Reply Quote 0
              • ajb2k3A
                ajb2k3
                last edited by

                As far as I am aware, the core doesn't have one!
                The silver, M5go and fire have them.

                UIFlow, so easy an adult can learn it!
                If I don't know it, be patient!
                I've ether not learned it or am too drunk to remember it!
                Author of the WIP UIFlow Handbook!
                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                K 1 Reply Last reply Reply Quote 0
                • K
                  ken57093 @ajb2k3
                  last edited by

                  @ajb2k3
                  Okay... Thanks a lot!

                  ajb2k3A 1 Reply Last reply Reply Quote 0
                  • ajb2k3A
                    ajb2k3 @ken57093
                    last edited by ajb2k3

                    @ken57093 在 How to use the angle sensor? 中说:

                    @ajb2k3
                    Okay... Thanks a lot!

                    your talking about the white thing?
                    Sorry i was confused as i dont have the white thing

                    Digitalread returns 1?

                    Looks connected, try analogread() on 22 (not spelt correctly)

                    UIFlow, so easy an adult can learn it!
                    If I don't know it, be patient!
                    I've ether not learned it or am too drunk to remember it!
                    Author of the WIP UIFlow Handbook!
                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                    K 1 Reply Last reply Reply Quote 0
                    • K
                      ken57093 @ajb2k3
                      last edited by ken57093

                      @ajb2k3
                      Yes, the white thing is the angle sensor and i connect it to the M5 Core. The Digitalread returns is 1.

                      I had tried analogread() on 22 but cannot get the angle change on the serial monitor (Its always 0).

                      Do you have any ideas?

                      ajb2k3A 1 Reply Last reply Reply Quote 0
                      • ajb2k3A
                        ajb2k3 @ken57093
                        last edited by

                        @ken57093
                        Sorry posting while half asleep.
                        According to the datasheet GPIO22 in on pin 39 however, grove specs should have it as not connected in analogue read mode.
                        Just checking the various documents and according to them you may want GPIO 21 which is on pin 42 (again sorry, i'm half asleep and rushing to work.)

                        Have you downloaded the esp32 data sheets and they are very usefull to read through?

                        UIFlow, so easy an adult can learn it!
                        If I don't know it, be patient!
                        I've ether not learned it or am too drunk to remember it!
                        Author of the WIP UIFlow Handbook!
                        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                        K 1 Reply Last reply Reply Quote 0
                        • K
                          ken57093 @ajb2k3
                          last edited by

                          @ajb2k3
                          Thank you.
                          Do you mean changing "#define ROTARY_ANGLE_SENSOR 22" to "#define ROTARY_ANGLE_SENSOR 21"?

                          I changed 22 to 21 but there is no difference except digitalread() of 21 is always 1.

                          ajb2k3A 1 Reply Last reply Reply Quote 0
                          • ajb2k3A
                            ajb2k3 @ken57093
                            last edited by ajb2k3

                            @ken57093 gpio22 in NOT on pin 22 gpio is on pin 49 according to the datasheet

                            Opps there are only 48 pins. the define should be 39!

                            #define ROTARY_ANGLE_SENSOR 39

                            UIFlow, so easy an adult can learn it!
                            If I don't know it, be patient!
                            I've ether not learned it or am too drunk to remember it!
                            Author of the WIP UIFlow Handbook!
                            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                            K 1 Reply Last reply Reply Quote 0
                            • K
                              ken57093 @ajb2k3
                              last edited by ken57093

                              @ajb2k3
                              Thank you.

                              I had tried. There is no change when i steer the sensor, but the value will sometime auto change itself.

                              0_1538616378269_a7f8a7a8-1392-43b3-900e-6c3c292aed61-image.png

                              ajb2k3A 1 Reply Last reply Reply Quote 0
                              • ajb2k3A
                                ajb2k3 @ken57093
                                last edited by ajb2k3

                                @ken57093 , sorry, will try setting up a test rig and test.
                                Haybin said to try 36!

                                UIFlow, so easy an adult can learn it!
                                If I don't know it, be patient!
                                I've ether not learned it or am too drunk to remember it!
                                Author of the WIP UIFlow Handbook!
                                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                                K 1 Reply Last reply Reply Quote 0
                                • K
                                  ken57093 @ajb2k3
                                  last edited by

                                  @ajb2k3

                                  I had tried before. The output of 36 is similar to 39.

                                  ajb2k3A 1 Reply Last reply Reply Quote 0
                                  • ajb2k3A
                                    ajb2k3 @ken57093
                                    last edited by ajb2k3

                                    @ken57093 在 How to use the angle sensor? 中说:

                                    Ok, set up my test rig and getting the same results.
                                    This is my code and I think something is missing.

                                    #include <M5Stack.h>
                                    /macro definitions of Rotary angle sensor and LED pin/
                                    #define ROTARY_ANGLE_SENSOR 36
                                    #define LED 3 //the Grove - LED is connected to PWM pin D3 of Arduino
                                    #define ADC_REF 3.3 //reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
                                    //board switches to 3V3, the ADC_REF should be 3.3
                                    #define GROVE_VCC 3.3 //VCC of the grove interface is normally 5v
                                    #define FULL_ANGLE 180 //full value of the rotary angle is 300 degrees
                                    void setup()
                                    {
                                    M5.begin();
                                    Serial.begin(9600);
                                    pinMode(ROTARY_ANGLE_SENSOR, INPUT);
                                    pinMode(LED,OUTPUT);
                                    }
                                    void loop()
                                    {
                                    float voltage;
                                    int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
                                    voltage = (float)sensor_valueADC_REF/1023;
                                    float degrees = (voltage
                                    FULL_ANGLE)/GROVE_VCC;
                                    Serial.println("The angle between the mark and the starting position:");
                                    Serial.println(degrees);
                                    }

                                    UIFlow, so easy an adult can learn it!
                                    If I don't know it, be patient!
                                    I've ether not learned it or am too drunk to remember it!
                                    Author of the WIP UIFlow Handbook!
                                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                                    1 Reply Last reply Reply Quote 0
                                    • ajb2k3A
                                      ajb2k3
                                      last edited by

                                      OK analogue read does not work, the command is something like ADC1 get raw (or some such)

                                      UIFlow, so easy an adult can learn it!
                                      If I don't know it, be patient!
                                      I've ether not learned it or am too drunk to remember it!
                                      Author of the WIP UIFlow Handbook!
                                      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                                      1 Reply Last reply Reply Quote 0
                                      • lukasmaximusL
                                        lukasmaximus
                                        last edited by

                                        I can get a readout from the angle sensor on both the serial console and lcd with this sketch. Try it out and see if it works for you. I'm using the m5go but the pinout should be the same. Make sure you connect the black wire to gnd, the red wire to 5v and the white wire to 36

                                        <code>

                                        #include <M5Stack.h>

                                        void setup()
                                        {
                                        M5.begin();
                                        M5.Lcd.setBrightness(30);
                                        M5.Lcd.clear();

                                        }

                                        void loop()
                                        {
                                        M5.Lcd.setCursor(160, 120);
                                        int adc = analogRead(36);
                                        M5.Lcd.println(adc);
                                        Serial.println(adc);
                                        delay(2);
                                        }
                                        </code>

                                        ajb2k3A 1 Reply Last reply Reply Quote 0
                                        • K
                                          ken57093
                                          last edited by

                                          @lukasmaximus

                                          Thank you. But i just have this wire and I use your code still unsuccess.
                                          http://forum.m5stack.com/assets/uploads/files/1538465243067-20181002_152122-resized.jpg

                                          1 Reply Last reply Reply Quote 0
                                          • ajb2k3A
                                            ajb2k3 @lukasmaximus
                                            last edited by

                                            @lukasmaximus 在 How to use the angle sensor? 中说:

                                            I can get a readout from the angle sensor on both the serial console and lcd with this sketch. Try it out and see if it works for you. I'm using the m5go but the pinout should be the same. Make sure you connect the black wire to gnd, the red wire to 5v and the white wire to 36

                                            <code>

                                            #include <M5Stack.h>

                                            void setup()
                                            {
                                            M5.begin();
                                            M5.Lcd.setBrightness(30);
                                            M5.Lcd.clear();

                                            }

                                            void loop()
                                            {
                                            M5.Lcd.setCursor(160, 120);
                                            int adc = analogRead(36);
                                            M5.Lcd.println(adc);
                                            Serial.println(adc);
                                            delay(2);
                                            }
                                            </code>

                                            My self and Ken are using the grove port which is pin 22&23 and so can't move it over to a different port.
                                            @ken57093 - I haven't forgotten about you my friend, I just been busy trying to finish some of my backlog of projects which the M5Stack is proving to be very usefull for.

                                            UIFlow, so easy an adult can learn it!
                                            If I don't know it, be patient!
                                            I've ether not learned it or am too drunk to remember it!
                                            Author of the WIP UIFlow Handbook!
                                            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                                            K 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post