cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with a black pill board programmed via the Arduino IDE

robotics_beginner
Associate

Hello, all. I am currently trying to program a black pill board to print out the output from a sound sensor, for which I use the Arduino IDE 2.3.2. 

Used components:

- STM32F411CEU6 black pill
- KY-037 sound sensor

Current connections:

- the "G" pin from the sensor is connected to the "GND" pin on the black pill
- the "+" pin from the sensor is connected to the "3v3" pin on the black pill
- the "A0" pin from the sensor is connected to the "A9" pin on the black pill

The code:

 

 

#define DIGITAL_INPUT PA9

void setup() {
  Serial.begin(9600);
  pinMode(DIGITAL_INPUT, INPUT);
}

void loop() {
  Serial.println(analogRead(DIGITAL_INPUT));
}

 

 

This code prints out values around 270-290 and it doesn't seem like creating any loud noises has any effect on the output, and neither does changing the potentiometer on the sensor itself. What I am trying to get is an output that has a clear and visible change between different amounts of noise. I am starting to think that the current output is just the floating value of the "A9" pin.

Other relevant info:

- I believe the problem isn't in the black pill itself, since I can successfully implement a simple "blink" functionality.
- I have already adjusted the potentiometer on the sensor so that the L2 is off. It turns on briefly when it detects a noise (such as clapping or anything louder).
- Changing the pin from "A9" outputs values from different ranges, but those values still don't seem to be affected by any noise, no matter how loud.
- The values don't change if "A9" is connected to the "A0" pin on the sensor instead of "D0".

If anyone can offer some assistance, I would majorly appreciate it.

1 ACCEPTED SOLUTION

Accepted Solutions
robotics_beginner
Associate

I double-checked the contact on the black pill pins and it seems that it fixed the issue. Apparently the contacts on all the pins were a bit weak, so I reinforced them a bit and now I am getting an actual output. Now I get values around 690 in silence, with different jumps in value depending on the sounds I make. I can't believe it was such a trivial thing afterall.

I appreciate you all helping me out and I wish you the best of luck in your future endeavors. Have a great day!

View solution in original post

9 REPLIES 9
robotics_beginner
Associate

Quick correction for the last point in other relevant info. The values don't change if "A9" is connected to the "D0" pin on the sensor instead of "A0".

The sensors seems to.give high or low. So  you should not use analog read.  Chek with a multimeter if the output changes.      https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/

mwalt.3
Associate II

Hi , you need to use an analog pin

I already am. Is A9 not analog?

What do you mean "high or low"? The sensor has both an analog output pin and a digital one. If I use digitalRead, I just get a constant output of "0", even when I can clearly see that L2 is on.

jafarhansla
Visitor

It seems like you're facing an issue with reading the analog output from the KY-037 sound sensor. Let's troubleshoot the problem:

1. Pin Configuration
The `A0` pin on the KY-037 is the analog output, which should be connected to an analog input pin on your STM32F411CEU6. However, in your code, you defined `DIGITAL_INPUT` and connected it to `PA9`, which is not an analog pin on this board. This would result in the analogRead function not working as intended.

**Solution**:
Change the `PA9` pin to an actual analog pin on the STM32F411CEU6, such as `PA0` (which is `A0` on the Arduino IDE for this board). Update your code accordingly:

 

void setup() {
Serial.begin(9600);
pinMode(ANALOG_INPUT, INPUT);
}

void loop() {
Serial.println(analogRead(ANALOG_INPUT));
}

2. Potentiometer Adjustment
The KY-037 has a potentiometer that adjusts the sensitivity of the microphone. Ensure that this is set correctly. Since you mentioned the L2 LED briefly turns on when it detects noise, this indicates that the sensor is working, but the analog output might not be responding correctly.

3. Power Supply
Ensure that the sensor is receiving adequate power (3.3V in your case). Some sensors may behave unpredictably if they don't get sufficient power.

4. Testing with Another Board
If you have another board, such as an Arduino, you could test the sensor there to ensure that it's functioning correctly. This will help you isolate whether the issue is with the sensor or the STM32 setup.

5. Serial Monitor
Make sure the Serial Monitor is set to the correct baud rate (9600 in your case) and that you’re observing the data in real-time.

Try making these adjustments and see if the output values start reflecting changes in the noise levels. If the issue persists, we can further troubleshoot.


@robotics_beginner wrote:

I already am. Is A9 not analog?


https://stm32world.com/wiki/Black_Pill 

Alright, I've tried these out. The sensor does indeed get its 3.3V, the Serial Monitor is set to the correct baud rate as well, and I moved the connection onto "PA0" (with the updated code). So far no luck. The output now revolves around 270-275, but still doesn't seem to respond to any sounds I make.

I have also tried connecting it to an Arduino board (Arduino UNO, to be exact), and it actually seems to be working. In silence, the output is stationary at 694, but it also gets above 1000 and below 300 when I make some louder noises. I also tried printing the digital output instead, which normally stays at 1, but it changes to 0 a lot of the time when I make a loud enough noise, so I guess that works too.

I'm not sure why it isn't working on the black pill. I used the same wires, so the issue isn't their contact. Could be the contact on the black pill itself? If not, the only other thing I can think of is that maybe something's up with the code, might be missing something if STM boards need some additional initialization or something when being programmed with Arduino. 

robotics_beginner
Associate

I double-checked the contact on the black pill pins and it seems that it fixed the issue. Apparently the contacts on all the pins were a bit weak, so I reinforced them a bit and now I am getting an actual output. Now I get values around 690 in silence, with different jumps in value depending on the sounds I make. I can't believe it was such a trivial thing afterall.

I appreciate you all helping me out and I wish you the best of luck in your future endeavors. Have a great day!