How do I get the GPIO expansion pins to work with input devices (e.g., Distance Sensor)? - google-aiy

I'm trying to use an HC-SR04 distance sensor with the AIY voice kit. I used the setup in the image link below, except using bonnet PIN_A and PIN_B instead of RPi GPIO23 and 24, and I used a 1000 Ohm and 2000 Ohm resistor for the voltage divider (rather than a 330 and a 470).
gpiozero docs distance sensor basic recipe
Here is my script:
from gpiozero import DistanceSensor
from time import sleep
from aiy.pins import PIN_A
from aiy.pins import PIN_B
sensor = DistanceSensor(echo=PIN_A, trigger=PIN_B)
while True:
print('Distance to nearest object is ', sensor.distance, 'm')
sleep(1)
When I run it, I get the following error:
Traceback (most recent call last): File "sensor_demo.py", line 6, in
sensor = DistanceSensor(echo=PIN_A, trigger=PIN_B) File
"/usr/lib/python3/dist-packages/gpiozero/devices.py", line 124, in
call self = super(GPIOMeta, cls).call(*args, **kwargs) File
"/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 856,
in init partial=partial, ignore=frozenset({None}),
pin_factory=pin_factory File
"/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 277,
in init pin_factory=pin_factory) File
"/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 197, in init
super(EventsMixin, self).init(*args, **kwargs) File
"/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 103,
in init self.pin.pull = pull File
"/usr/lib/python3/dist-packages/gpiozero/pins/init.py", line 337, in
lambda self, value: self._set_pull(value), File
"/home/pi/AIY-projects-python/src/aiy/pins.py", line 605, in _set_pull
'Only pull up is supported right now (%s)' % pull)
gpiozero.exc.PinFixedPull: Only pull up is supported right now (down)
When I run it on a RPi 1 B+ directly (with RPi GPIO pins), it works fine, so I think it has to do with the GPIO expansion pins on the bonnet, especially when they are used for input, like here, here, and here.
Is there any way to make this work with the GPIO expansion pins, or do I have to take the RPi 0 out of the box and use its pins?

I analyzed the error and went through the gpiozero documentation. So according to the PinFixedPull error
Error raised when attempting to set the pull of a pin with fixed pull-up
So this is most likely a physical hardware issue with the pins because it says right on your error that only pull up is supported.

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?

GSM Telit GL865-QUAD AT command, error: 314 (SIM card busy)

I'm trying to communicate with GSM click module (Telit GL865-QUAD module) via UART with AT command. First I want to read all received messages, but for some reason I got error 314, meaning that SIM card is busy. Other answers from GSM are ok.
So this is my config (sending few at commands in a row):
AT\r\n (check GSM)
ATE0\r\n (echo disable)
AT+CMGF=1\r\n (set SMS text mode)
AT+IPR?\r\n (query current baud rate)
AT+CMGL=\"ALL\"\r\n (finally read all messages)
All commands have 1 second delay after gsm get positive (OK) answer. For example: send AT\r\n wait for OK and then wait 1 second; after that delay send another AT command.
Result: I got fine response from GSM when I sent first 4 AT command. But after the fifth one the modem returns error 310 (sometimes) followed by error 314:
AT+CMGL="ALL"
+CMS ERROR: 310
AT+CMGL="ALL"
+CMS ERROR: 314\r\n
I tried it with 2 different SIM cards and got same result.
Any idea or comment are welcome.
First of all, GE865-QUAD is an old device, so I recommend that you at least update it to the latest FW version. You can query current FW version of any GSM modem by issuing AT+CGMR AT command.
Edit: since you have a really old version (10.00.144 is dated 2009/2010!) I STRONGLY recommend updating it, since many bugs could have been fixed since then. You will be able to get last version from Telit site, and to flash it via UART.
Errors explanation
You seem to obtain error 314 preceeded, sometimes by error 310.
+CMEE Error: 314 means SIM busy, as correctly stated by your question subject
+CMEE Error: 310 means SIM not inserted
Possible solutions
First of all, make sure that the SIM is correctly inserted. It has to be pushed all its way in. I suppose you correctly inserted it, but a check has to be done.
Then, since you state that
I try with 2 sim cards and got same result.
I suggest you to check the contacts of the SIM holder (because it is unlikely that both your SIMs have bad electric contacts). In fact the SIM busy status, usually reached when a SIM is actually read (e.g. full phonebook) could also mean that some unconsistent action happened (also SIM failure massage can be shown in those cases).
Make sure you wait enough for SIM ready. In fact, even if SIM initialization usually takes less than a second, in some old SIM models might happen that a longer time is needed.
Telit provides a command to query SIM status: AT#QSS. As descripted by the AT guide, it enables an unsolicited message for any SIM status change. But it also allows allows, through its read command to query the status asynchronously:
AT#QSS?
Read command reports whether the unsolicited indication #QSS is currently enabled or not, along with the SIM status, in the format:
#QSS: mode,status
mode - the verbosity level of #QSS URC, set with AT#QSS=mode. Default value is 0; 2 enables the maximum verbosity level.
status - current SIM status
0 - SIM NOT INSERTED
1 - SIM INSERTED
2 - SIM INSERTED and PIN UNLOCKED (Note: available only if mode=2!)
3 - SIM INSERTED and READY (SMS and Phonebook access are possible) (Note: available only if mode=2!)
So you have to wait until status 3 is reached. I suggest issuing read command every 1/2 seconds until the desired status is reached. Issuing commands that involve the SIM storage before that status is reached will lead to SIM Busy error.
Very important: since status=3 will be shown only with mode=2, issue the following concatenated AT command in order to discover if the SIM INSERTED and READY status has been actually received without enabling URCs:
AT#QSS=2;#QSS?;#QSS=0
In this way, mode=2 is set just before the read command so that the full status list is supported. Then mode is restored to value 0, avoiding URCs to appear.
Make sure that the PIN has been inserted!
The SIM could be locked with the PIN code. Verify it by querying AT+CPIN?. If the response is +CPIN: SIM Ready you are fine. Otherwise, If the response is +CPIN: SIM PIN, you have to insert the PIN code by issuing
AT+CPIN=<PIN>
I found what was problem. Power supply for GSM did not have enough Amps.. For GSM you must provide 3.3V and 3A from power supply unit. GSM don't have 6.5W power consumption if you think that GSM need 3A all the time. GSM have peaks of current up to 2A and thats why you need more Amps.

Arduino Ultrasonic Distance Sensor with Passive Buzzer to achieve different tones

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.

Rpi wheezy duplicate capture on usb & dummy cards

I am trying to create an application that will stream audio with Darkice as well as provide a LED VU meter indication of the audio stream.
I have created a virtual card with . This card is recognized by alsamixer, aplay, and arecord but I can not transfer the line-in signal from the usb card (hw:0,0) to the dummy card (hw:2,0).
I have tried several .asoundrc scripts that I found both in your Q&A as well as Google using alsa dmix, dsnoop, and multi but nothing has worked so far.
I am presently using one python program (LED_VU.py) that autostarts in one terminal, and the second python program containing Darkice (streamer.diDual.py) in a second terminal. The configuration portion of the LED program is:
### LED VU Meter on RPI ###
#!/usr/bin/env python
import alsaaudio as AA
import audioop
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
#Define physical header pin numbers for 10 LEDs
RPiPins=[11,12,13,15,16,18,22,7,3,5]
#set all pins as output
for pin in RPiPins:
GPIO.setup(pin, GPIO.OUT)
#Set up audio
card = 'hw:0,0'
The configuation portion of darkiceDual.cfg is:
# Darkice Configuration File - Generated by Streamer
[general]
duration = 0 # duration of encoding, in seconds. 0 means forever
bufferSecs = 5 # size of internal slip buffer in seconds
reconnect = yes # reconnect to server if disconnected
[input]
device = hw:2,0 # alsa usb soundcard device for audio input
sampleRate = 44100 # sample rate in Hz
bitsPerSample = 16 # bits per sample
channel = 2 # channels. 1 = mono, 2 = stereo
My .asoundrc file is:
pcm.!default {
type plug
slave.pcm "mdev"
route_policy "duplicate"
}
pcm.mdev {
type multi
slaves.a.pcm "hw:0,0"
slaves.a.channels 2
slaves.b.pcm "dmixer"
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:2,0"
period_time 0
period_size 1024
buffer_size 4096
rate 44100
channels 2
format S16_LE
}
}
What am I doing wrong?
The streamer will have no audio if I use hw:2,0 and have the 'Can not connect' error if I use hw:0,0 (LED_VU.py is using this). If I change the card setting of the LED program to hw:2,0 the LEDs will lockup with all of them lit.
Any help is appreciated!
Thank you for the help. The two programs both use the usb line-in as expected.
I am not able to use alsamixer or amixer now. Pulseaudio is causing the problem now. If it is installed, the LED_VU.py program will not run. When it is uninstalled, the python programs will run but not alsamixer.
Apparently, you want to run the VU meter and DarkIce from the same audio data, i.e., you need to allow two programs to share one recording device.
This can be done with the dsnoop plugin. Which is enabled by default for USB devices.
Tell both programs to record from the device default. If that was redefined, try dsnoop:0 instead.

Generation of RTE_Components.h

I'm working with MDK-Pro and the File System library.
In my application, I require an SPI interface to the SD card. I've managed to setup the project properly, except that in the RTE_Components.h file that Keil generates the line #define RTE_Drivers_MCI0 which subsequently triggers a preprocessor error ("SDIO not configured in RTE_Device.h").
Although I can manually comment out this line in RTE_Components.h, every so often Keil updates this file and I get the above problem. Does anyone know what exactly generates this file, and how I can stop it from adding the SDIO-related definitions into the project?
The RTE_Components.h is not supposed to be modified and will always be automatically generated. That the stack tries to connect via MCI interface is related to your configuration made in the "FS_Config_MC_0.h".
// <o>Connect to hardware via Driver_MCI# <0-255>
// <i>Select driver control block for hardware interface
#define MC0_MCI_DRIVER 0
// <o>Connect to hardware via Driver_SPI# <0-255>
// <i>Select driver control block for hardware interface when in SPI mode
#define MC0_SPI_DRIVER 0
// <o>Memory Card Interface Mode <0=>Native <1=>SPI
// <i>Native uses a SD Bus with up to 8 data lines, CLK, and CMD
// <i>SPI uses 2 data lines (MOSI and MISO), SCLK and CS
// <i>When using SPI both Driver_SPI# and Driver_MCI# must be specified
// <i>since the MCI driver provides the control interface lines.
#define MC0_SPI 1

Resources