Greetings all. Rpi newby with a couple of Qs:
1) I'm trying to make a GPIO output (p1 pin 12) the opposite of another (p1 pin 11). First I tried GPIO.output(12, not 11) but no joy so then I tried GPIO.output(12, not GPIO.input(11)) & success. How come I have to read pin 11 to invert it? Why can't I just invert it's output register? I'm worried that when I change 11 to an input to read it it's just dumb luck that the result happens to be it's previous output state.
2) I can't comment my code. Shift 3 gives a pound symbol instead of #. I've tried telling it I'm in Australia with a US keyboard in the internationisation in config but no luck.
Re: Inverting a GPIO pin
1) It is possible to GPIO.input() a channel setup as an output
2) Have you set up your keyboard using
You may need to reboot for the changes to take effect - I can't remember if this is the case or not.
2) Have you set up your keyboard using
Code: Select all
sudo raspi-config
-
- Posts: 7706
- Joined: Sat Jan 12, 2013 3:01 am
- Location: Grants Pass, OR, USA
- Contact: Website
Re: Inverting a GPIO pin
(For Raspbian OS)PlanB wrote:...
...
2) I can't comment my code. Shift 3 gives a pound symbol instead of #. I've tried telling it I'm in Australia with a US keyboard in the internationisation in config but no luck.
sudo raspi-config
- Choose Internationalization menu
- Choose keyboard setup menu.
- If your exact keyboard is not on the list then choose one of the generic 101, 102 or 104 keyboards.
The following steps are Important! If you need US then you must choose US. Don't leave it set to UK.......
- You may need to scroll down and select [Other] to get back to the country of origin menu
- From country of origin menu select [English (US) ]
- Then from Keyboard layout: menu scroll to top of list and select - [ English (US) ]. Do not choose anything else unless you know exactly what you are doing!
- Complete the other menus then reboot.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.
Re: Inverting a GPIO pin
Thnx people, # problem solved with a reboot after keyboard config. Re the pin inversion, what I really want to do is generate antiphase pwm. I can get PWM on one pin easily enough with
pwm=GPIO.PWM(12, 10) # setup pulse width mod on pin12 at 10 Hz
but how do I get a waveform on pin 11 going that is 180 degrees out of phase with the pin 12 waveform?
pwm=GPIO.PWM(12, 10) # setup pulse width mod on pin12 at 10 Hz
but how do I get a waveform on pin 11 going that is 180 degrees out of phase with the pin 12 waveform?
Re: Inverting a GPIO pin
thnx klricks the rdp is a bit more user friendly than the SSH. Surely I can get antiphase out of the Pi without resorting to external hardware Tao?
Re: Inverting a GPIO pin
Looks like it is possible, but..... what are you using the signal for?PlanB wrote:thnx klricks the rdp is a bit more user friendly than the SSH. Surely I can get antiphase out of the Pi without resorting to external hardware Tao?
The hardware PWM system has 2 channels which can be set to clock data out from a register called FIFO in the PWM system. If both channels are set to use FIFO then they each get data from alternate words in lock-step, this should be the root of your solution.
>)))'><'(((<
Re: Inverting a GPIO pin
There may be far easier solutions, but they would very much depend on how the PWM signal is expected to vary. For instance, if the PWM signal has a fixed duty cycle there are trivial solutions.
Re: Inverting a GPIO pin
Just need a pair of antiphase square waves Joan (fixed 50% duty cycle) so very interested to hear of your trivials to do this please.
Re: Inverting a GPIO pin
10Hz 50% duty cycle anti-phase on gpios 7/8.
http://abyz.co.uk/videos/antiphase.webm
7 and 8 chosen as I can remember the values of 1<<7 and 1<<8.
http://abyz.co.uk/rpi/pigpio/
http://abyz.co.uk/videos/antiphase.webm
7 and 8 chosen as I can remember the values of 1<<7 and 1<<8.
Code: Select all
sudo pigpiod
$ pigs m 7 w
$ pigs m 8 w
$ pigs wvag 128 256 100000 256 128 100000
2
$ pigs wvcre
0
$ pigs wvtxr 0
7
Re: Inverting a GPIO pin
Wow, impressive! So I have to load up C to do that? Is there a way to do it with the python that comes with noobs?
Re: Inverting a GPIO pin
It really depends on how much fidelity you want from the inverse signal. The example I gave will be perfect.PlanB wrote:Wow, impressive! So I have to load up C to do that? Is there a way to do it with the python that comes with noobs?
Does the signal need to be perfect? Would it matter if the signal drifted from 10Hz or if the inverse signal sometimes lagged by a few milliseconds?
Re: Inverting a GPIO pin
Pretty humble newby stuff. I'm just driving a bicolour 2 wire led on P1 pins 11 & 12. I can do green by holding pin 11 lo & PWMing 12, or red by taking pin 11 hi but I can't do orange (antiphase).
Re: Inverting a GPIO pin
I'd just try a Python script first of all and see if the results are acceptable.
Code: Select all
...
import time
...
while True:
write(GPIO1, 1) # Change write to what your Python module uses
write(GPIO2, 0)
time.sleep(0.1) # You probably want to change this to 0.01
write(GPIO1, 0)
write(GPIO2, 1)
time.sleep(0.1) # You probably want to change this to 0.01
Re: Inverting a GPIO pin
I forgot to mention the Pi is busy with some other processing intensive tasks so I really need to be using DMA style PWM, I can't afford to bog it down in a software loop.
Re: Inverting a GPIO pin
Having a Python thread to do the loop shouldn't put a significant additional load on the system, I guess 1% or so.PlanB wrote:I forgot to mention the Pi is busy with some other processing intensive tasks so I really need to be using DMA style PWM, I can't afford to bog it down in a software loop.
If you are determined to use hardware timing I think RPIO.GPIO is likely to give the lightest additional load and should do what you want. The pigpio Python module will work but has an overhead of about 5% (because of the 200kps gpio sampling going on in the background).
Re: Inverting a GPIO pin
Much obliged Joan. Is there a go to document that has all this detail on what packages have how much overheads?