Closed manj9501 closed 2 years ago
Here's the output with both Hex and human-readable format enabled:
4000800A8FFF7 -0.000000000010965 in 300499105CFFF 0.000000000910637 in F300499105CFF 0.000000000991064 in FF300499105CF 0.000000499105 in FFFF000566041 0.5660 in 330A8FFF70082 -0.01665701 in 00566041FFFF0 0.000000000042665 mm 000566041FFFF 0.000000000604266 in F000566041FFF 0.000000000660426 in FFFF000566541 0.5665 in 3B2A8FFF70082 -0.01665701 in 00566541FFFF0 0.000000000542666 mm 000566541FFFF 0.000000000654266 in F000566541FFF 0.000000000665426 in FF000566541FF 0.000000000566542 in FFF000566541F 5665.4 in FFFF000566541 0.5665 in 9515CFFF30049 166.5300 in
I can notice the bits getting shifted by themselves when the OLED is connected, can you please help me make more sense of this?
Can you please me please help me a bit with explaining how adding additional lines of code say, for instance, for adding a display or adding a delay would affect the execution of this program?
The getData()
method was written in a straightforward way. This is easy to write, to debug, and to understand, but is not robust against interruptions. This is very common in Arduino code people share online, including this project.
Adding Arduino libraries with background processing will cause interruptions and corrupt getData()
. For example, Arduino's standard PWM functionality (analogWrite()
) adds a hardware timer interrupt. I am not familiar enough with the Adafruit display library you have added, but this is the likely explanation based on output data you provided.
It is possible to rewrite getData()
to be robust against such things, but such complexity was out of scope for my toy project.
This is only a guess based on limited data, the real problem may be something else.
no display in the circuit / display connected in the circuit
Are you saying the data is corrupted if the display is electrically connected without software changes to communicate with that display? (Without Adafruit library.) If so, that hints at a power issue. Please use a voltmeter to verify all the components are receiving the power they need. Use a resistance meter to verify the 1k resistor is as expected, if the resistance is too low that pin may be drawing excessive power. The Mitutoyo indicator may need fresh batteries, etc.
Adding Arduino libraries with background processing will cause interruptions and corrupt
getData()
.
Appreciate your two cents on this! I was also thinking on similar lines, while analyzing the phenomenon.
Are you saying the data is corrupted if the display is electrically connected without software changes to communicate with that display? (Without Adafruit library.)
The code on the Arduino UNO is the same that I pasted in my initial comment, compiled with Adafruit library included. I get correct output on the serial when the OLED is not electrically connected in the circuit, but the moment I get connect it in the circuit, the corrupt data starts appearing on the serial monitor as well as the OLED. There's one more thing I noticed: even when the OLED is connected in the circuit, the corrupt data stops appearing when I am moving the height gauge. The moment I bring it to a stationary position, the corruption starts again.
Also I'll do the power checks at my end as well just to make sure.
Any more information to help diagnose this problem?
Closing due to insufficient information. Please feel free to reopen if more data for diagnostics become available.
Hi @Roger-random
My setup consists of a Mitutoyo Height Gauge 570-246 connected to an Arduino UNO.
Can you please me please help me a bit with explaining how adding additional lines of code say, for instance, for adding a display or adding a delay would affect the execution of this program? Asking this since I've connected an I2C SSD1306 OLED display and when I connected the display, I start getting garbage values, along with the correct values, on both the display and the serial. Noteworthy thing is that if I don't have the OLED connected, the code works just fine and outputs correct values to serial monitor all the time.
Code:
Normal serial output (no display in the circuit):
Abnormal serial output (display connected in the circuit):