Originally posted by Teleno;
Announcement
Collapse
No announcement yet.
Announcement
Collapse
No announcement yet.
Modified sketch for improved timing precision.
Collapse
X
-
Hmm, doesn't the analog voltage at TP10 cover +-5v ? The A1 input of the uP will only except positive 0..5v, are you relying on the uP input protection diode clipping the negative?
-
Here's the display code.Originally posted by SaltyDog View PostBe interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..
Place this snippet at the beginning of the sketch
PHP Code:#define USE_OLED
#ifdef USE_OLED
#include <Tiny4kOLED.h>
#include <font16x32digits.h>
const DCfont *largeFont = FONT16X32DIGITS;
const DCfont *smallFont = FONT8X16;
uint8_t width = 128;
uint8_t height = 32;
#endif
This snippet at the beginning of setup()
PHP Code:#ifdef USE_OLED
oled.begin(width, height, sizeof(tiny4koled_init_128x32br), tiny4koled_init_128x32br);
oled.setFont(smallFont);
if (smallFont->width == 0) {
oled.setSpacing(1);
} else {
oled.setSpacing(smallFont->spacing + 1);
}
oled.on();
oled.clear();
oled.setCursor(0, 2);
oled.print("DELAY");
oled.setCursor(0, 0);
oled.print("us");
oled.setFont(largeFont);
if (smallFont->width == 0) {
oled.setSpacing(1);
} else {
oled.setSpacing(largeFont->spacing + 1);
}
#endif
and this snippet in the loop()
PHP Code:#ifdef USE_OLED
oled.setCursor(70, 0);
oled.print(mainDelay);
oled.print(" ");
#endif
This is what you'll get
If you won't use the OLED comment out the "#define USE_OLED" line and rebuild. Otherwise Nano will wait forever for a display to be ready that doesn't exist.
Install the following libraries in Arduino (using search box)
Tiny4kOLED
TinyOLED-Fonts
The display is 0.91 inch OLED 128x32 based on controller SSD1306. Like this one: https://www.aliexpress.com/item/1005006431809403.html?
- Likes 1
Leave a comment:
-
To the administrators: Please delete my post #40 or replace it with this post. The resistor values shown were wrong and it could cause damage to the Nano board.
This is a second mod to allow not only increases in volume in the presence of a target, but also increases in pitch (frequency + ampitude modulation). The human ear is much more sensitive to changes in pitch than in amplitude, so this feature can result in an improved detection experience.
[ATTACH]n420152[/ATTACH]
To use the attached sketch you'll have to do the PWM mod first (swapping pins 8 and 10) as explained on page 3, post #15
This second mod connects the output of the amplifier (TP10) to analog input A1 of the Nano via a resistor divider. 56k from TP10 to A1, and 120k from A1 to GND. This limits the max. voltage at the analog pin to 5V.
If the frequency excursions are not broad enough try replacing this line:
with this:PHP Code:word freq = map(target, 10, 1024, FREQ_MIN, FREQ_MAX);
PHP Code:word freq = map(target, 512, 1024, FREQ_MIN, FREQ_MAX);
Leave a comment:
-
No, this must be done outside in the field, as inside there is too much interference from metal and electronic noise.Originally posted by Gunghouk View Post
Couldn't you initially serial print to a laptop to see the values in a bench setting? If the pot value is enough then put a DVM on the wiper and measure using a 10 turn pot.
Leave a comment:
-
I will. But that's anything anyone here could do, since the loop() is fully available. Find a display of choice, get the library and insert the code in the sketch. It doesn't matter how heavy the library is cause the MCU here does basically nothing and the memory use is minimal.Originally posted by SaltyDog View PostBe interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..
you could even add a videogame too
)
With this sketch you can set the default main sample delay all the way down to zero. There is no latency. Just edit the define "defMainDelay" to be as early as your coil allows
Leave a comment:
-
Be interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..Originally posted by Teleno View Post
Actually I've attached a 128x32 OLED and can see the delay in real time. My eyes are not so good anymore so I'm looking for big fonts. Will post the code when I'm satisfied with it.
Leave a comment:
-
This is a second mod to allow frequency modulation depending on tatget strength. You'll get a signal that not only increases in volume in the presence of a target, but also increases in pitch.
Aduino_PI2_F_modulation.zip
To use the attached sketch you'll have to do the PWM mod first (swapping pins 8 and 10) as explained on page 3, post #15
This second mod connects the output of the amplifier (TP10) to analog input A1 of the Nano via a resistor divider. 47K from TP10 to A1, and 56K from A1 to GND. This limits the max. voltage at the analog pin to 5V.
If the frequency excursions are not broad enough try replacing this line:
with this:PHP Code:word freq = map(target, 10, 1024, FREQ_MIN, FREQ_MAX);
PHP Code:word freq = map(target, 600, 1024, FREQ_MIN, FREQ_MAX);
Leave a comment:
-
We're on the same boat.Originally posted by Gunghouk View PostAnother thought couldn't the audio frequency be tied to the delay setting?
... my search for relief from retirement boredom.
Certainly you can fiddle with the audio frequency, but keep in mind that it uses Timer2 wich is also used by Arduino's analogWrite(), so it will break this function. Anyway it's not used anywhere in the sketch, so that isn't a problem for this project.
So here's some code. Add these lines to the setup() function
PHP Code:/**
* URL: https://dbuezas.github.io/arduino-web-timers/#mcu=ATMEGA328P&timer=2&timerMode=CTC&topValue=OCR2A&OCR2A=126&CompareOutputModeA=toggle&clockPrescalerOrSource=128
* Mode : CTC
* Period : 1 ms
* Frequency: 1 kHz
* Outputs :
* - B3: 50.00%, toggle
*/
TCCR2A = 1 << COM2A0 | 1 << WGM21;
TCCR2B = 1 << CS22 |1 << CS20;
DDRB |= 1 << DDB3;
OCR2A = 127;
Delete or comment out this line:
PHP Code:analogWrite(audioPin, 127); // Set audioPin with 50% duty cycle PWM
The value OCR2A sets the frequency. A value of 128 gets you 490 Hz. A value of 60 gets you 1Khz, and proportionally the other values in between.
So if you want the mainSample delay to modulate the tone you map the values like this:
Place this line in the loop().
PHP Code:OCR2A = map(mainDelay, defMainDelay, 20, 60, 128);
Then you'll hear 1 KHz at minimum delay of 10us and gradually decreasing to 490 Hz at delay 20us. Set the limits as you will.
- Likes 1
Leave a comment:
-
Another thought couldn't the audio frequency be tied to the delay setting?
You'll have to excuse any dumb or obvious statements I make as this is my first excursion into metal detecting and Arduinos as part of my search for relief from retirement boredom.
Leave a comment:
-
Certainly, now just send me some gold, haha!Originally posted by Gunghouk View Post
Couldn't you initially serial print to a laptop to see the values in a bench setting?
Actually I've attached a 128x32 OLED and can see the delay in real time. My eyes are not so good anymore so I'm looking for big fonts. Will post the code when I'm satisfied with it.
Leave a comment:
-
Couldn't you initially serial print to a laptop to see the values in a bench setting? If the pot value is enough then put a DVM on the wiper and measure using a 10 turn pot.Originally posted by Teleno View PostNice teamwork! Huge shoutout to you for fearlessly rewiring your box and patiently testing multiple versions of my mod. Without your feedback I couldn't have ironed out the devilish details.
Curious about how the sensitivity with this mod compares to previous.
What you say about the delays and gold, it's probably time to populate the now deserted loop() with code to drive some cheap I2C OLED display from the Chinese supplier and visualize what the actual delays are. We then can tune the range in code.
Leave a comment:

Leave a comment: