Arduino Ultrasonic Distance Sensor with Passive Buzzer to achieve different tones - c

I have an Ultrasonic Distance Sensor with Passive Buzzer. The passive buzzer was set up with different tones. The buzzer will keep playing until the Ultrasonic Distance Sensor detect any obstruction items. However, the Arduino couldn't compile the code. it displays the error:
exit status 1
Error compiling for board Arduino/Genuino Uno.
Here is the full error message:
Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I could locate the function timer0_pin_port in Tone.cpp.o. But I couldn't find the same function in NewPing.cpp.o.
Because of the space limit, I counldn't post the NewPing.cpp.o here. You can download the NewPing.cpp.o here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
Tone.cpp.o is the original document in the library.
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 10 // Maximum distance we want to ping for (in centimeters).
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
pinMode(2,OUTPUT);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
if (sonar.ping_cm() == 0)
tone(2,4000);
else
tone(2,0);
}
Expected: The Buzzer will stop playing when the DIstance sensor detects any items. You have to use tone method to support different Tones. Or any similar functions that can support different tones.

From what I understand that the Tone and the NewPing library have a conflicting use of the same interrupt __vector_7. NewPing is known to have conflicting issues, I would suggest you use the original ping in Arduino. Here's a comprehensive example for it.
If you're certain that you're not using the ping_timer() method then in the NewPing.h file make TIMER_ENABLED to false.
Here's a link which talks about Multiple Definition of "__vector_7" Error further.
Here's the thread of a similar problem on the arduino forum.

Related

MTK 7628 openwrt failed to add pps driver

I use a chip from MTK7628,Currently, the kernel supports pps processing. Because the pps of my ublox is connected to gpio, i use make menuconfig and choose gpio mode
enter image description here
Because my chip does not support modifying the device tree,so i creat a dev-pps.c file in /home/luke/MtkOpenwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.10.14/arch/mips/ralink, write the following code and compiled it into the firmware
enter image description here
When I write the firmware into the chip, the system will prompt the following error
enter image description here
Gpio 11 is connected to PPS and has been set to GPIO mode,this pin is not occupied either.I don't understand why the error "failed to request GPIO 11" is displayed.
About "probe of pps-gpio failed with error -22",I can not find a solution online.
Later, i use make kernel_menuconfig and choose gpio mode, turn off the PPS option in make menuconfig, as a result, after burning the firmware, the system will prompt the same error as before.
enter image description here
How do I resolve these two errors now?

STM32CubeIDE Break at address "xxx" with no debug information available, or outside of program code

I'm busy bring up some new hardware with a STM32F030C8 mcu. I'm using the STM32CubeIDE with gcc. I'm very new to microcontroller development and this is my first project with ST and their tools.
This is a very basic program that just triggers a GPIO. The rest is all generated code. As I have very little experience in this field I hope somebody can point to a location where I can look. I suspect that it might be a configuration issue.
Here is the code (I removed all generated comments to keep it a bit more compact):
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2); //my code 1
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2); //my code 2
while (1)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2);
HAL_Delay(1000);
}
}
When I step through the code It will trigger the GPIO on "my code 1" once I step to "my code 2" it will cause the issue. I have even tried just running a fully generated program with no modifications and the issue persists. This was a quick test to see if the program actually does run on the mcu. And it does, as well as trigger the GPIO.
Debugger console Output:
Temporary breakpoint 1, main () at ../Core/Src/main.c:74
74 HAL_Init();
Program received signal SIGTRAP, Trace/breakpoint trap.
0x1fffecec in ?? ()
The Temporary breakpoint is where the program starts, I can then either run from there. Or step through, all with the same result.
Console Output:
Waiting for debugger connection...
Debugger connected
-------------------------------------------------------------------
STM32CubeProgrammer v2.4.0
-------------------------------------------------------------------
ST-LINK SN : 34FF6E065250343816210143
ST-LINK FW : V2J36S7
Voltage : 3.22V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x440
Device name : STM32F05x/F030x8
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M0
Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_PEkdAh.srec
File : ST-LINK_GDB_server_PEkdAh.srec
Size : 4944 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:
File download complete
Time elapsed during download operation: 00:00:00.627
Verifying ...
Download verified successfully
Full Error:
Break at address "0x1fffecec" with no debug information available, or outside of program code.
Here is two images that might help. As I mention I'm very new to this. So any other information required please ask. Thanks in advance.
Debug View
Disassembly
The code is placed at 0x08000000. There is no user code at 0x1fffecec. It system area and probably it boots the system bootloader. It shows that the BOOTx pin is incorrectly connected.

GNU ARM Eclipse: how to simulate pin input?

I want to pass sine wave data onto a pin (any possible one), so that my program would be able to read it when being run in an emulator.
How how can I pass data in the form of (time:value) or just pass a function float generatorForPinX(int time); to act as signal generator into the GNU ARM Eclipse (I use QEMU but if any other emulator is required I am willing to migrate) board emulator?
These instructions are for emulating an Olimex STM32 P103 Development Kit.
Download and build
First download and build Qemu STM32, which includes patches for emulating the ADC peripheral on the STM32:
wget https://github.com/beckus/qemu_stm32/archive/stm32.tar.gz
tar xf stm32.tar.gz
cd qemu_stm32-stm32
./configure --target-list="arm-softmmu"
make
cd ..
If the configure step fails, then install the missing requirements. See the README for more information.
Then download the Olimex STM32 P103 Development Kit Demos:
wget https://github.com/beckus/stm32_p103_demos/archive/master.tar.gz
tar xf master.tar.gz
Look in stm32_p103_demos-master/demos/adc_single/main.c for an example program which uses the ADC.
Run the demo application
To build and run the adc_single demo:
cd stm32_p103_demos-master
QEMU_ARM_DIR=../qemu_stm32-stm32/arm-softmmu/ make adc_single_QEMURUN_TEL
(from another terminal) telnet localhost 7777
UART2 is attached to the telnet server on port 7777, which you should see output from. See the README for more information on how to build and run the demo applications.
Looking at the source for the adc_single demo application, it has 3 different modes:
Mode 1 (the default) will read from the temperature sensor on ADC channel 16
Mode 2 will read the Vdd value from ADC channel 16
Mode 3 will read from ADC channel 8.
The modes can be selected by using a button, but since we are emulating the hardware with QEMU, the button is not available. I switched between the modes by changing the int mode = 1; value and recompiling the program.
ADC emulation
The method that QEMU uses to emulate each ADC channel is viewable in the stm32_adc_start_conv function in hw/arm/stm32_adc.c:
static void stm32_adc_start_conv(Stm32Adc *s)
{
uint64_t curr_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
int channel_number=stm32_ADC_get_channel_number(s,1);
// Write result of conversion
if(channel_number==16){
s->Vdda=rand()%(1200+1) + 2400; //Vdda belongs to the interval [2400 3600] mv
s->Vref=rand()%(s->Vdda-2400+1) + 2400; //Vref belongs to the interval [2400 Vdda] mv
s->ADC_DR= s->Vdda - s->Vref;
}
else if(channel_number==17){
s->ADC_DR= (s->Vref=rand()%(s->Vdda-2400+1) + 2400); //Vref [2400 Vdda] mv
}
else{
s->ADC_DR=((int)(1024.*(sin(2*M_PI*qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)/1e9)+1.))&0xfff);
}
s->ADC_SR&=~ADC_SR_EOC; // jmf : indicates ongoing conversion
// calls conv_complete when expires
timer_mod(s->conv_timer, curr_time + stm32_ADC_get_nbr_cycle_per_sample(s,channel_number));
}
As you can see, ADC channel 16 will emulate a random Vdd input, ADC channel 17 will emulate a random temperature input, and all other channels will follow a sine wave from 0 to 2048. Here is a graph of the ADC values returned from all 3 modes:
If you want to have an ADC channel use a different emulation pattern, you can modify stm32_adc_start_conv and rebuild QEMU following the steps above.

Serial port not sending data

Yesterday, I started with some serial port communication. Today, I tried to open exactly the same sketch I used yesterday. It worked, but a few minutes later when I uploaded it again, it doesn't work at all.
Here's the code:
#include "Blink_main.h"
int pin = 1;
void pulsePin(int abc, int length){
digitalWrite(abc, true);
delay(length);
digitalWrite(abc, false);
}
void setup() {
pinMode(pin, OUTPUT);
Serial.begin(9600);
Serial.println("Hi serial!");
pulsePin(pin, 1000);
}
void loop() {
if(Serial.available() > 0){
Serial.println(Serial.read());
pulsePin(pin, 1000);
}
}
When opening the application, I don't see the "Hi serial!" message, When sending something, I don't get a message back and I don't see the LED flashing. Why is this happening?
You are using pin 1 to blink the led, move the led to another pin since it is used as the serial TX
Digital Pins 0-1/Serial In/Out - TX/RX - These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin).
It look like the problem come from the Arduino board.
Firstly, try to upload a Serial example sketch.
If it doesn't work, try to reinstall the driver or change the COM port used.
If the problem is still happening, it's probably the ATMEGA8U2 or ATMEGA16U2 which is dead. You can test with an external USB to UART convert directly on pins 0 and 1

Program halts while sending byte to USB-to-Prallel (D-Sub 25pins) port

I have an USB to 25-pin parallel port cable. I connected it to laptop and get a port at /dev/usb/lp0, then I connect pin1/pin25 of parallel port with +/- LED it lights.
Now I move +pin of LED to pin 2 of parallel port, and try to send byte to port , it should light up but it doesn't. following is my c code in linux.
#include<stdlib.h>
#include<stdio.h>
#include<sys/io.h>
void main(void)
{
int port=0x378;
outb(0xff,port);
outb(0x01,port+2);
sleep(1);
outb(0x00,port+2);
printf("‌​End");
}
this is my complete program, I also checked it with port=0x3bc but did not work. Even I checked strobe pin 1 by connecting + of LED, it alsways lights but does not go low. May be there is problem with port address.
for /dev/usb/lp0 I also used command line command like $echo $'\xFF' > /dev/usb/lp0 I observed that it does something but does not light up the LED. When I connect LED with pin2 and 25 as + and -. I can see a very little light in side the LED in the beginning but when I run above command that very tiny light disappears but LED does not glow high like it does when I connect it with strobe pin. Also I can only execute above command only two times. Third and later times I thing command does not work while it seems halted.
Can any one help why it halts or how can I get LED switch on/off on data pins? Thanks

Resources