[Solved]How to use the angle sensor?
-
@ken57093 , sorry, will try setting up a test rig and test.
Haybin said to try 36! -
I had tried before. The output of 36 is similar to 39.
-
@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 = (voltageFULL_ANGLE)/GROVE_VCC;
Serial.println("The angle between the mark and the starting position:");
Serial.println(degrees);
} -
OK analogue read does not work, the command is something like ADC1 get raw (or some such)
-
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> -
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 -
@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. -
@ajb2k3
Haha, it's fine. I almost give up trying the angle sensor myself. Now I'm trying to use the SIM800L GSM module. -
My apologies guys, I presumed you were using the m5go or fire as I am. If you are using the gray or black core models you will need to use jumper cables to attach the angle sensor to the pins on the bottom of the core as shown in this picture. it is not possible to connect the angle sensor to 22 or 23 as they are digital inputs, for the angle sensor we need an analog input or ADC (analog to digital converter) pin, so this is only possible on pins 35 and 36. try to connect as I show in these pictures and try again, it should display the numbers on both the serial monitor and the screen.![](http://imagehosting.biz/image/6ut
http://imagehosting.biz/image/6u0) -
Thank you. I will try it again after buying the wire