GPIO on Raspberry Pi
Posted
#1
(In Topic #440)
Trainee
Public Sub Form_Open()
'determine GPIO 23 = Pin 16 as Input / pull-up Resistor to +Ub
Shell "gpio -g mode 23 in up"
' enable Timer1 for polling
Timer1.Enabled = True
Timer1.Delay = 100
Shell "gpio -g read 23" 'read the content of pin 16
' If…
End
I´m far from sure if this is even going - I would need to know the state of pin 16 where the geigercounter is connected to - a negative edge means a count - the counts have to be added for one minute to get the cpm (counts per minute) - then the values could be displayed and/or written to a logfile. My Bascom program used Interruptprogramming for this purpose - I don´t know if this is possible with Gambas.
Now my question is how do I transfer the value of pin 16 to variable? Is there a better method for polling an input pin in Gambas?
Posted
Guru

If you double-click on the Timer you put on the form Gambas will take you straight to the timer routine I think you need. The routine will be called every 10th of a second (Timer1.Delay = 100).
If you define a variable before any subroutines it will be global. You can then use the shell command to send the result to your variable: -
I would need to see more of your old code to work out exactly what you are after but I hope this is a start.
I have moved these posts to the General Forum
Posted
Regular

phb said
…I wrote a program in BASCOM for my selfmade Geigercounter to measure natural background radiation. Now I´m trying to convert this program to the raspberry pi using Gambas…
Hi Peter, I'm wondering what the output from your Geiger counter looks like. I assume its a series of random pulses. If that is the case, what's the minimum time between pulses?
Your timer is set for 100ms, which I would have thought is too slow to detect more than 1 pulse in 100ms.
Using interrupts on a Raspberry Pi is probably not the answer either (see my old blog post: Captain Bodgit: RaspberryPi inputs: to poll or to interrupt?).
I would have thought you needed some binary counter logic in your Geiger counter, and then maybe read 4 bits at a time (using 4 digital i/o lines on the Pi) and then clear the counter ready for the next count.
However, I'm probably way off the mark in my understanding of what you are trying to do.
Posted
Trainee
I would need to see more of your old code to work out exactly what you are after but I hope this is a start.
Hello cogier - thanks for the warm welcome!! Here is the desired code and many thanks for your prompt answer - that´s what I needed!!!!!!
P.S: sResult - shouldn´t it be Integer? That´s what represent the counts and they have to be added…but when I try to make sResult Integer I get an error message :(
$regfile "ATtiny13.DAT"
$crystal = 96000000
$hwstack = 32
$swstack = 8
$framesize = 16
'—————————————————————————
Dim Counts As Integer 'Declaration
Counts = 0 'of
Dim Sekunden As Integer 'the variables
Sekunden = 0 'all values to 0
Const Timervalue = 40 'equals 1 second at 9,6 MHz
'—————————————————————————
Led Alias Portb.0 ' Led connected to PORTB.0
Led = 0 ' for making the counts visible
Config Led = Output ' not needed for the actual program
'—————————————————————————
Config Portb.1 = Input 'PortB.1 (INT0) - where signal from geigercounter arrives
'—————————————————————————
On Int0 On_int0 'declaring Label "On_int0"
Config Int0 = Falling 'Interrupt at falling edge
Enable Int0
Enable Interrupts
'—————————————————————————
Config Timer0 = Timer , Prescale = 1024
Enable Timer0
Timer0 = Timervalue ' Timer0 is charged with "Timervalue" = 1 second
On Timer0 Timer_interrupt
'—————————————————————————
Open "comb.3:9600,8,n,1,INVERTED" For Output As #1
' activate Software-UART on Attiny13 - TX is PORTB.3
'—————————————————————————
Do
!nop 'mainprogram - no Action!
Loop
End
'—————————————————————————
On_int0: 'on interrupt jump to this label
Incr Counts ' Increment Counts on each Interrupt
Led = 1 ' LED is blinking on each Count
Waitms 10
Led = 0
Return 'back to the main program when done
'—————————————————————————
Timer_interrupt: 'jump to this label once in a second
'increment by 1 each second
Incr Sekunden
If Sekunden = 60 Then 'after 60 seconds counting of events is done
Then
Sekunden = 0
Print #1 , Counts 'send value to the serial as counts per minute (cpm)
Counts = 0
End If
Return
Posted
Trainee
Thanks for your answer!! The pulses are needle like - falling edge type - from +5V to 0V. They are not exact standard but every controller could detect them easily so far. Background radiation is in average 37 pulses per minute in my case so that 100 ms is far enough for me - if 100 ms becomes too little to detect each pulse maybe than I don´t need a geigercounter anymore (atomic bomb, china syndrome, gamma ray burst
You must know that the geigercounter is about to become a part of my private weatherstation. It was connected to a pc of mine before and ran only when th pc was turned on - now I intend to run the counter permanently on my Pi.
I had a program written in liberty basic that wrote the values to a logfile - I have quite a lot of them now. But that program is no longer working for unknown reasons - it´s a windows program of course
Posted
Guru

Posted
Trainee
Code
Let iPin = 23
Let iTime = 60000
Dim iCounter As Integer
Dim sStatus As String
Dim tStart As Float = Timer
Dim tStop As Float
Shell "gpio -g mode " & iPin & " in"
Shell "gpio -g mode " & iPin & " up"
Repeat
Shell "gpio -g read " & iPin To sStatus
Wait
If Val(sStatus) = 0 Then Inc iCounter
tStop = Timer
Until (tStop - tStart) > iTime
Shell "gpio -g mode " & iPin & " down"
Return iCounter
Public Function Label1_ShowCounts() As Integer
Label1.text = GPIO_Count(23, 60000)
End
Code
Posted
Enthusiast

but anyhow … take a form put a (text)label and a (command)button on it …
in the class file:
something like that …
p.s.: ich empfehle dir dringend einen blick in https://gambas-buch.de/
Posted
Regular

Just a question, why you don't use Wiring Pi
GPIO Interface library for the Raspberry Pi
It's more suitable for your application.
Regards from France
Olivier
Posted
Trainee
Cheers
Matt
Matt
Posted
Regular

Regards
Posted
Trainee
This is a Gambas class, so create a new class file in your project called "GPIO_Pin" and copy and paste the code into it…
https://raw.githubuser…aster/.src/GPIO_Pin.class
Then in your code:
Let me know how you get on / if this is helpful ?
Happy Christmas
Cheers
Matt
Matt
Posted
Regular

Just, I've no question
I was just answering to the forum topic, personally i use wiringpi with a real success
Regards and Happy Christmas
Olivier
Posted
Trainee
Cheers
Matt
Matt
Posted
Regular

Matthew-Collins said
…can you post a WiringPi example…
RPi GPIO Code Samples - eLinux.org
Note: 1) I don't think you need root for latest wiringPi,
2) Gordon got the 'ump with abuse, so stopped updating wiringPi some time ago: Captain Bodgit: Never look a gift horse in the mouth
Posted
Trainee
However, on the off chance that you need them, there are various new equipment fringe drivers that can be alloted to GPIO's, relatively few individuals use them yet, so there isn't a lot of information about them, however
Notwithstanding the heritage peripherals we have:
4 new PL011 UARTs with fair measured FIFOs
4 new I2C regulators with fixed (or diversely broken) clock extending
4 duplicates of the old SPI regulator
Turnkey PCB Assembly - Bittele Electronics
1 guest and 0 members have just viewed this.


