I dont know why is this happening but am quite pissed off :-), because am struggling with this for two days now..
HW:
Arduino board --> Raspberry Model 2 B
Am sending one second impulse from arduino mega digital pin 8 to raspberry.
I added voltage divider so i have clean 3,25V impulse.
RSP reads most of impulses correctly but sometimes i get false readings.
E.g. one impulse is triggered and few are not or it starts to trigger impulses but I didn't send any from arduino side.
I try with pullup, pulldown setup but the problem is the same.
Maybe i should define that the "impulse" is value that last 1 second and everything else is "garbage" ?. If so, how to make this ?
CODE:
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
...
GPIO.Cleanup()
The funny part is that if i test the impulse from RSP 3,3V pin, it works every time ( of course with pull_down setup ). So, what could be a problem ?
3,3V and 3,25 is no difference at all and RSP defines HIGH from 2.8 - 3.3V...
Any ideas ?
For me, it's more a matter of electronic.
In fact, for that kind of library, we can assume that the functions work correctly (I suppose that you wrote correct code that was built like that: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/).
I believe that the electronic problem can come from several sources:
Either your ground is badly connected (or it's not the same for the arduino and the rasperry pi). So, the reference tension isn't the same and a 0V for the arduino can be 1V for the raspberry pi.
It can also be a result of a bad interpretation of when your circuit is on and off. Don't forget that to put a plain 0V in the input of the raspberry pi (when the circuit is off). You need to explicitly write 0V at the output of the arduino (I mean: digitalWrite(ledPin, LOW);) otherwise your pin would not be "grounded" but "floating" and the tension can fluctuate from any value (close to 0) to another depending on environmental factors.
(to achieve it, you can also use pull down resistances, see: http://playground.arduino.cc/CommonTopics/PullUpDownResistor).
It can also be a transient phenomenon due to unwanted capacitive reactions. So, when your current changes quickly, the circuit cannot follow it instantaneously and it will produce some voltage glitches.
I suggest checking the two first points. If it cannot solve your problem, it should be related to the second point and you could handle it with capacitors and wait times.
I hope it will help :)
Thank you for replay. This are the test's that I made today.
- I have connected the zener diode to get the 3,3v and this part is good
- tested with different impulse lengths
None of them worked.
It's interesting, if i start the RSP script and if i just wait for impulse ( without triggering it ) i will get some 30 reading in few minutes. So it looks like that there is something going on.
I disabled this part of the code in arduino, but i still get this readings...
Btw. should i connect arduino and rsp GND together ?
E.
Related
Project Aim: Create a seat that when you sit on it, audio starts. When you leave, the audio stops. Next time someone sits down, the audio begins again. Each time it is a random track, different from the last.
Context: Outside with access to power
How it can work (I think): I’m wondering if it is possible with using a Raspberry Pi and PIR Sensor (plus some other bits and pieces?). Basically, when someone moves into the range of the PIR sensor, this event is detected and sends an input to a GPIO pin on the Pi. With the right script, this can then fire an event – e.g. play a random audio file from micro SD card. Does this sound correct/doable?
Help!: I believe its not too abstract an idea or function, that has probably been done before. But I just can’t seem to find exactly what I’m looking for, where someone has already written a script I can use/modify. So I’d love to know, do you think this idea is doable/achievable? And, where acatly do you recommend I can track down a pre-made script/instruction on making it a reality.
If you know someone who could write such a script, please do put me in contact.
Thanks!
This is actually not that hard to realize. You have to come up with an idea for a sensor that you can build into your chair, I would recommend just a simple one that works like a push button: when someone sits down, you got a connection the RasPi can recognize. After doing that make sure, your RaspberryPi has power, a GPIO connection to the sensor and speakers attached.
The Script is also quite simple and its structure would look like this:
import RPi.GPIO as GPIO
import simpleaudio # just as an example, was the first one I found online
sound = 'path/to/your/soundfile.wav'
def playSound(directory):
play = simpleaudio.WaveObject.from_wave_file(directory)
play.play()
try:
while True:
if GPIO.input(numberofyourgpio):
play_sound(sound)
except KeyboardInterrupt:
pass
Finally you can set this to start after booting the RaspberryPi and you will never have to care about it not being started anymore.
I am an absolute N00b when it comes to Python and I have no idea how to turn my 'sudo'- code into actual code.I'm also having issues with the GPIO pins in my pi.
I would very much like some help coding this project.
I've tried making separate codes to test the GPIO pins but they never seem to work properly, I'm not using any resistors and I probably should even though I have no idea which ones and where.
I have tried to use the Bluetooth speaker with my pi but it always seems to prefer the HDMI even though I try to force it to Bluetooth, it just won't go.
I have been learning python in my free time as much as I can but since I am a full-time student, I haven't been able to learn very much and my knowledge of c++ has been entirely useless so far.
This is my sudo code
loop(called while on)
if(handset is on the cradle)
Do nothing and loop “while on” again
else
Clear Code
loop(called dialing loop)
If (time<3seconds)
Play dialtone.mp3
if(number indicator is off)
Stop playing dialtone.mp3
Reset time
Count number of pulses from #pulser
Assign number to the next letter of Code
Exit to dialing loop
Else
Start counting time
Exit to dialing loop
Else
Search thumbstick for Code.mp3
if (Code.mp3 exists)
Play Code.mp3
Exit to while on loop
Else
Play dropped call.mp3 for 3 seconds
Exit to dialing loop
My goal is to use an old rotary phone with a raspberry pi that will let you dial a number (arbitrary length) an audio file associated with that number (one file per number-one number per file) will be played through the handset. My restrictions are: the files and codes must be read from a thumb drive, there must not be a cap on the number of files, there must not be a cap on the length of the number you can dial, all the outward facing parts of the phone must look like the original phone, it must be a raspberry pi. the dial on the phone uses two leaf switches, one that pulses an amount of times based on the number that is dialed and one that is active until a user starts to dial a number. There is a needle switch attached to the cradle that will detect whether or not the handset is on the cradle and the audio is being played through a Bluetooth speaker.
You could always start here: https://leanpub.com/RPiMRE
You can read it online for free: Here's a section on GPIO:
https://leanpub.com/RPiMRE/read#leanpub-auto-pin-header-1
Again it's free and a good resource with code examples on how to map what you're looking to do for your project. It might not be straight away what you're looking for but might have some bits that can help you. Good Luck!
I'm looking for some help 'cause I'm getting a bit frustrated on this... :-(
I have a headless Raspberry PI 3 with a PiFi DAC+ audio card, basically an HiFiBerry clone. On the PI I installed mpd and mpc as a client.
On top of those I wrote a python script that invokes some mpc commands to control the underlying mpd daemon (load a playlist, play a stream,...).
Now the issue.
The overall audio setup based on the hifiberry-dacplus overlay works well, the sound is good and I'm fine with it. Mpc & mpd work, I can control all the functionalities of mpd (at least the ones I need) through mpc without a flaw...but, if I try to run my python script suddenly I cannot hear anything anymore, even if no specific errors are traced.
The 'scary' thing is that, after aborting the script execution, I'm no more able to play any sound (I tried with several wav files using aplay), and again no specific errors show up in the log files...looks like someone just 'muted' the volume, but alsamixer shows all playback levels to 100%. I need to reboot the PI to get my sound back.
I checked for clues in the usual places:
/var/log/messages
/var/log/syslog
dmesg
boot.log
/var/log/mpd/mpd.log
I also run aplay -vvv when audio was blocked and compared the output with a session where audio was running fine but I didn't notice any difference...
I know it would be very difficult to diagnose the problem without having access to my system, but do you have any ideas on where else to look to understand if something went wrong?
Just for info, here's my aplay -l output:
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
Thank you!
Michele
EDIT: seems like there is some incompatibility between the audio board and a 16x2 LCD display I'm using to show the name of the stream I'm playing. The display is a very common one, based on the HD44780 chip.
My code uses the AdaFruit python library available here to drive it and I still have to figure where the problem is: the audio board, as per HiFiberry docs is connected through GPIO 2,3,18,19,20,21 (plus ground & +5V for power), so it shouldn't cause any conflict with the LCD which uses different pins, but I wouldn't bet on it.
Anyway, removing the LCD management part from the python code (but leaving the display physically attached to the RaspBerry pins) apparently solved the problem...
I'll keep this question updated, maybe could be useful for someone else, who knows!
Ok, I got it. As usual, I just went too fast with CTRL-C & CTRL-V without properly reading the code...
I didn't notice I left this statement in my python code
lcd_backlight = 2 #GPIO pin to control lcd backlight
Actually The GPIO 2 (which is one of the two I2C enabled pins on the Raspberry) is not connected to the LCD, but it is used by the audio board for configuration purposes: this way, whenever I tried to initialize the LCD, the audio board was somehow reconfigured, making it "mute". The only way to reset the faulty configuration was to reboot the PI itself.
Just leaving the default 'None' value for the backlight control pin (I do not need it) did the trick.
I haven't found a useful answer to my problem from the many forums I've found. If you know one please comment a link below.
I have a Raspberry Pi Zero and an Arduino Fio w/ an Xbee module. I'm currently trying to do a simple test with the Zero and an Arduino Uno just to practice serial communication. I only need the Zero to receive data and not transmit, which is what several forums only direct towards. I want to take an integer from a compass heading (received by the Xbee from a beacon unit at some distance away).
So for my practice I send an integer on the Arduino using Serial.write(). On the Zero I simply use python and the library pyserial with the function serial.readline(). Also, yes, I've stepped the Arduino tx pin's voltage to 3.3 volts and I know the Zero is receiving a transmission. When I set the Arduino integer to say 39, the Zero will (with a print function) show the ASCII character corresponding to the hex value of 39 which is 9 (but it is a string not an integer).
In essence, my dilemma is I can't figure out how to convert the transmission to an integer that I can use trig with to make calculations. Firstly, I'm not sure if it's possible to make a fix on the Arduino side. Secondly, if it can be on the Zero, I'm not familiar enough with the pyserial library to know how to fix it. In addition to my second point, I've tried type casting it with int(string) to convert it to a string. I get an error code saying that the operation is invalid with an operator of base 10 (or something close to that).
I'm currently at my home and do not have access to my code on either the Arduino or Zero so please talk to me first instead of complaining 'show code'. I'm an experienced programmer and adept enough to talk through complications. Thank you.
I am trying to connect the Black Swift with an display from Parallalax[1]. I have been reading lots of tutorials about that but with the displays being used on the tutorials there is always a difference to the pins on my display. The displays that are being used usually have lots of pins where you can choose the ones you need, but the display I have just has 3 pins (5V, GND, RX). Now I assume that with this RX pin I can control the display (like when I use lots of pins on other displays). But I dont know where to connect that RX pin on my Black Swift. The next thing is,
I have also read the manual on that display I have (the link I provided) but the examples they use there are all built up on some boards that are being sold on the website (for example nothing about how to connect a raspberry or arduino). When reading a tutorial everything seems pretty easy, but I guess I didnt choose my hardware wisely :(
Now my question, since I am new to this, is it possible to connect that display to some random microcontroller (in my case Black Swift) ? If yes, where should I connect that RX pin? What is this RX pin doing, (didnt find anything in the manual about that)? Since they are using some special way (PBasic?) to control the display (is inside the manual), is it be possible to control the display with pythong?
Thanks for the help
EDIT:
So far I have managed to turn on/off the UART mode, and it seems that this is not the issue bcz I am getting same results (weired characters on te display).
[1] https://www.parallax.com/sites/default/files/downloads/27979-Parallax-Serial-LCDs-Product-Guide-v3.1.pdf
The linked PDF tells the story pretty conclusively. You need a UART from your controller with the matching bps-rate as set up by the DIP-switches.
Following http://www.black-swift.com/wiki/index.php/File:BlackSwift-1.0-pinout.png you should connect GPIO10/UART_TX to the RX, and then program your uC in whatever language it supports.