Hi
Why atan on oscilloscope is correct = strait about 30deg line but on serial plotter not = it is vary from 10 to - 140deg ?
// DC bias 2000
float Ux ;
float Uy ;
float Uxb ;
float Uyb ;
int DEG;
void setup()
{
Serial.begin(115200);
}
void loop()
{
Ux = analogRead(PA0);
Uy = analogRead(PA1);
Uxb = Ux - 2000; //bias
Uyb = Uy - 2000; //bias
// DEG = degrees(atan2(Ux, Uy));
DEG = degrees(atan2(Uxb, Uyb));
Serial.print(" DEG = ");
Serial.print(DEG);
Serial.print(" 10 = ");
Serial.print(10);
Serial.print(" -140 = ");
Serial.print(-140);
Serial.println();
delay(20);
}
Try this.
// DC bias 512 (ADC 0..1023)
const float dcBias = 512;
float
Ux,
Uy,
DEG
;
void setup ()
{
Serial.begin ( 115200 );
}
void loop ()
{
Ux = analogRead ( A0 ) - dcBias;
Uy = analogRead ( A1 ) - dcBias;
DEG = degrees ( atan2 ( Uy, Ux ) );
Serial.print ( DEG );
Serial.print ( ',' );
Serial.print ( 180 );
Serial.print ( ',' );
Serial.println ( -180 );
delay ( 100 );
}
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
Are you sure you're comparing "apples" with "apples" ?
What are the data-points (Ux, Uy) for your comparison and what do they represent (imaginary, real, polar coordinates). Might be missing a conversion or using the wrong data type.
Perhaps your answer is here .
gcjr
May 20, 2023, 2:33pm
5
can you post your values of Ux and Uy?
Ux and Uy are from synchronous detectors taken through capacitors from U2A/U2B
https://radiolocation.tripod.com/NewDQandBeaconFiles/DQsimpleMainSchematic.htm
Pins 1 and 7
gcjr
May 20, 2023, 3:46pm
8
tom321:
deg512×738 15.3 KB
can you cut them from the serial monitor and post them like code?
1 Like
gcjr
May 20, 2023, 3:47pm
9
what you posted isn't including the Ux and Uy values used to compute the angle. please add them
tom321
May 20, 2023, 3:53pm
11
gcjr:
post them like code
DEG = -127.02 UxB = -183 UyB= -138
DEG = -131.87 UxB = -280 UyB= -251
DEG = -136.53 UxB = -310 UyB= -327
DEG = -136.44 UxB = -271 UyB= -285
DEG = -114.97 UxB = -146 UyB= -68
DEG = -2.67 UxB = -9 UyB= 193
DEG = 14.33 UxB = 129 UyB= 505
DEG = 15.67 UxB = 188 UyB= 670
DEG = 17.70 UxB = 201 UyB= 630
DEG = 12.75 UxB = 105 UyB= 464
DEG = -13.28 UxB = -55 UyB= 233
DEG = -105.99 UxB = -164 UyB= -47
DEG = -135.33 UxB = -257 UyB= -260
DEG = -140.09 UxB = -312 UyB= -373
DEG = -140.33 UxB = -311 UyB= -375
DEG = -135.19 UxB = -297 UyB= -299
DEG = -126.91 UxB = -233 UyB= -175
DEG = -109.68 UxB = -151 UyB= -54
DEG = -49.04 UxB = -91 UyB= 79
DEG = -22.72 UxB = -67 UyB= 160
DEG = -11.81 UxB = -37 UyB= 177
DEG = -27.88 UxB = -64 UyB= 121
DEG = -95.40 UxB = -127 UyB= -12
DEG = -126.75 UxB = -221 UyB= -165
DEG = -135.79 UxB = -285 UyB= -293
DEG = -135.64 UxB = -265 UyB= -271
DEG = -62.94 UxB = -92 UyB= 47
DEG = 21.98 UxB = 348 UyB= 862
DEG = 26.23 UxB = 917 UyB= 1861
DEG = 28.61 UxB = 1129 UyB= 2070
DEG = 26.47 UxB = 1011 UyB= 2
dlloyd
May 20, 2023, 4:09pm
12
Thanks, looks like the main board schematic from here . Beyond my expertise so I'll sit this out.
gcjr
May 20, 2023, 4:23pm
13
the values you posted match the values calculated on my laptop for atan2 (x, y)
but arguments to atan2 are typically (y, x)
(y,x) ( x,y) x y
-142.98 -127.02 -183 -138
-138.13 -131.87 -280 -251
-133.47 -136.53 -310 -327
-133.56 -136.44 -271 -285
-155.03 -114.97 -146 -68
92.67 -2.67 -9 193
75.67 14.33 129 505
74.33 15.67 188 670
72.30 17.70 201 630
77.25 12.75 105 464
103.28 -13.28 -55 233
-164.01 -105.99 -164 -47
-134.67 -135.33 -257 -260
-129.91 -140.09 -312 -373
-129.67 -140.33 -311 -375
-134.81 -135.19 -297 -299
-143.09 -126.91 -233 -175
-160.32 -109.68 -151 -54
139.04 -49.04 -91 79
112.72 -22.72 -67 160
101.81 -11.81 -37 177
117.88 -27.88 -64 121
-174.60 -95.40 -127 -12
-143.25 -126.75 -221 -165
-134.21 -135.79 -285 -293
-134.36 -135.64 -265 -271
152.94 -62.94 -92 47
68.02 21.98 348 862
63.77 26.23 917 1861
61.39 28.61 1129 2070
0.11 26.47 1011 2
tom321
May 20, 2023, 4:46pm
14
gcjr:
but arguments t
That will be another angle of the triangle but will not make angle constant as on oscilloscope (straight line )
gcjr
May 20, 2023, 4:51pm
15
as i said, the values are correct for args (x,y)
the result of atan2(x,y) is 90 (Pi/2) - atan2(y,x)
tom321
May 20, 2023, 5:06pm
16
The problem is not in the numbers, but why does the serial plotter have large variable angle values while the oscilloscope does not
gcjr
May 20, 2023, 5:14pm
17
bear in mind that the serial plotter is not an x,y plotter. it plots each value on a line as a separate plot.
can you post the output you send to the serial plotter captured on the serial monitor?
tom321
May 20, 2023, 5:24pm
18
It is not what is on post #11 ?
gcjr
May 20, 2023, 5:36pm
19
assuming the serial plotted ignores the "DEG=" it's just going to sequentially plot the numeric values as three separate plots
the serial plotter is not an x-y plotter
tom321
May 20, 2023, 5:49pm
20
Thanks I will look for solution.