[SOLVED] SwitchDoc Labs WeatherRack - GPIO to grovepi.digitalRead


#1

Hello All,
Has anyone managed to convert PIO commands like below to python Grove Pi digital input.
For example:
GPIO.add_event_detect(pinAnem, GPIO.RISING, callback=self.serviceInterruptAnem)
Which I believe detect’s a pulse from an magnetic switch from a Anemometer connected to pinAmen (GPIO Numbering Mode GPIO.BCM pin23).
Am I right in thinking that once a pulse is detected the program goes to :
def serviceInterruptAnem(self,channel):
where the pulse is counted.

If I am right would the Anemometer to digital port D5
pinAnem = 5
grovepi.pinMode(pinAnem,“INPUT”)
if grovepi.digitalRead(pinAnem) == 1:
self.serviceInterruptAnem()
Sadly when I try this approach nothing happens.

Can some suggest how I should code in python so the GrovePi Digital Ports are used.
What I am trying to achieve is to tweak Switchdoc Labs Weatherrack Python code https://github.com/switchdoclabs/SDL_Pi_Weather_80422
SDL_Pi_Weather_80422.py
Hoping someone can help
Michael.


#2

Hi @whimickrh,


Can you confirm you’re using this sensor (link)?
This is how it should look:


First of all, let me summarize a little bit about the board. Correct me if I’m wrong.

This board communicates through the following ports:

  • an I2C port
  • 2 interrupt pins

Since the data that’s extracted from the sensor is time-sensitive, we need the interrupt pins for triggering the Interrupt Service Routines in order have an exact measurement of the delay between readings. Having these kinds of measurements helps up calculate things like wind speed.


By reading your post, I assume you want to connect this board to the GrovePi board through the Grove connectors.

You can do that, but I don’t think it’s going to work.


The hard way is make it work with the GrovePi firmware, what you should do is to write some specific routines for the firmware, work on the communication protocol for the firmware and then make additional changes for the Raspberry Pis software.
And at the end, you’ll have a more inefficient solution since all the polling must be done through I2C (from the Raspberry Pi to the GrovePi).
It’s going to be a Rube Goldberg machine.


The simpler solution is to connect the I2C port from the sensor board to the GrovePi board and get the other 2 interrupts connected to some GPIO ports on the GrovePi header. You won’t be able to use the Grove connector for the interrupt pins, but you can wire them to the header by using some jumpers.

Please don’t use pin 24 since that one resets the GrovePi board. So pin 24 corresponds to GPIO 8 on the Raspberry Pi. Please take a look at the following pin-out. Please avoid using that pin.

After you get all the things wired up, you can program on the Raspberry Pi : make some routines for the interrupts and read the values via the I2C port.


Please, let me know if there’s anything else you want to know.

Thank you!


#3

Thanks for yor reply.

I will give up trying to use the GrovePi ports ans stick to the GPIO for the Anemometer and
Rain.

I have another qustion for you.

In recent week I have been getting this error.

engine: Caught unrecoverable exception in engine:
May 14 00:45:57 Whimick_Met weewx[4713]: **** ‘int’ object has no attribute 'getitem
May 14 00:45:57 Whimick_Met weewx[4713]: **** Traceback (most recent call last):
May 14 00:45:57 Whimick_Met weewx[4713]: **** File “/home/weewx/bin/weewx/engine.py”, line 871, in main
May 14 00:45:57 Whimick_Met weewx[4713]: **** engine.run()
May 14 00:45:57 Whimick_Met weewx[4713]: **** File “/home/weewx/bin/weewx/engine.py”, line 187, in run
May 14 00:45:57 Whimick_Met weewx[4713]: **** for packet in self.console.genLoopPackets():
May 14 00:45:57 Whimick_Met weewx[4713]: **** File “/home/weewx/bin/user/Raspi_Met.py”, line 602, in genLoopPackets
May 14 00:45:57 Whimick_Met weewx[4713]: **** [leaf_wetness, soil_moisture, solar_wm2] = self.analog()
May 14 00:45:57 Whimick_Met weewx[4713]: **** File “/home/weewx/bin/user/Raspi_Met.py”, line 346, in analog
May 14 00:45:57 Whimick_Met weewx[4713]: **** leaf_wetness = round(grovepi.analogRead(water_sensor) / 100, 2)
May 14 00:45:57 Whimick_Met weewx[4713]: **** File “/home/pi/Desktop/GrovePi/Software/Python/grovepi.py”, line 226, in analogRead
May 14 00:45:57 Whimick_Met weewx[4713]: **** return number[1] * 256 + number[2]
May 14 00:45:57 Whimick_Met weewx[4713]: **** TypeError: ‘int’ object has no attribute 'getitem
May 14 00:45:57 Whimick_Met weewx[4713]: **** Exiting.

Using this code below:

	while True:
		try:
			light_reading = float(grovepi.analogRead(light_sensor) / 2.5)
			leaf_wetness = float(grovepi.analogRead(water_sensor) / 100)
			soil_moisture = float(grovepi.analogRead(soil_sensor) / 100)
		except ArithmeticError, TypeError:
			error = False
			continue

After this error the software becomes un-usable and the only way to recover is a reboot, restaring the python script causes the same error

Should I reflash the GrovePi or is there another problem.

The script will run for many hours and fail at random.

Michael


[SOLVED] SwitchDoc Labs WeatherRack - TypeError Exception
#4

Hi @whimickrh,

Whenever you want to catch multiple exceptions in one exception block, you must group them into a parenthesized tuple.

Here’s how it has to look:

	while True:
		try:
			light_reading = float(grovepi.analogRead(light_sensor) / 2.5)
			leaf_wetness = float(grovepi.analogRead(water_sensor) / 100)
			soil_moisture = float(grovepi.analogRead(soil_sensor) / 100)
		except (ArithmeticError, TypeError):
			error = False
			continue

This will also ensure the code is forward-compatible with Python 3.


But when we don’t have the parenthesized tuple, only the first exception that’s specified is considered. In this case, only ArithmeticError exceptions are caught.

If we have a longer list of named exceptions such as except ImportError, KeyboardInterrupt, CustomExcept : the only exception that’s going to be caught is the ImportError.


Hope this helps you.
Thank you!


#5

Robert,

Thankyou for you recent email, I will take a futher look at error codes, but not until Thursday, as tomorow I’m busy with our CubScout pack’s cooking competition.

Please can you keep this thread open so I come back to you after tomorrow.

Thanks for taking time to help.
Michael


#6

Robert,
This morning it failed again, and since I had a few spare minutes, I ran the all_tests.sh, and am sending you the log.
Is my GrovePi working OK according to the logs?

Micahellog.txt (6.0 KB)


#7

Hi @whimickrh,

It seems like your software and hardware are perfectly functional.


Can you post here the code you’re trying to run (the one that gives you the error)?
We’ll try to see if there’s anything to change in it.

In order to keep having a clean look, please continue using the code preformatting tool as you’ve already used.


I’ll keep the thread open. Don’t worry.

Thank you!


#8

Hi Robert,
Thanks for your help. I have attached my python v2 script.
collectes data from a grovePi and sends data to Weewx and makes a number of text files.

Hoping you can helpRaspi_Met.py (20.7 KB)

Michael


#9

Hi @whimickrh,

I’ve tried running for a couple of hours the code I’ve shared in my previous post (the one containing the exception tuple), and I haven’t experienced anything out of the ordinary.


While running the script on the Raspberry Pi, I removed the GrovePi board from the header pins and the script went on running and I was getting the following error:

  • TypeError: 'int' object has no attribute 'getitem'

Till now, we get the expected results. It’s normal for the Raspberry Pi to throw such an error because there’s no GrovePi plugged in.

Now, plugging the GrovePi board into the Raspberry Pi while the script is running is going to get the Raspberry Pi reset.


Getting back to your problem, I think you may have some improper electrical contacts, which can lead to a reset of the Raspberry Pi.

Can you share with us some close-up pictures of the GrovePi and the Raspberry Pi?


Thank you!


#10

Robert,
Photo as requested
Michael


#11

Hi @whimickrh,

Thank you for sharing this screenshot.


By looking over the log.txt file, I can see there some inconsistencies.
Can you try running the Raspbian For Robots and then test your code?
Please, burn your micro SD card with the image found here.

And unfortunately, the picture isn’t too clear (I can’t see how the pins between the Raspberry Pi & GrovePi are binding), so I think we should go the other way.
Can you show me a screenshot of the program failing while you’re running it?

As a final note, I still think there are bad electrical contacts that are causing the program to fail.


Thank you!


#12

Hi Robert,

I will download the Image over night, and give it a try. I will also swap the Light sensor cable to if that is what is causing the errors. I will also re-photo the board and email it to you ans email you tomorrow.
I a have attached a log file showing another set of errors.

Many Thanks Michael.Screen.txt (5.9 KB)
Raspi_Met_ERROR_log.txt (1.2 MB)


#13

Hi Robert,

Just thought I would let you know, I ran this script to test the analog sensors only, and I am now unable to read them without an error.
I have also changed the cables.
I now downloading Rasbain for Robots and will try it and let you known what happens.

analog.py (2.0 KB)


#14

Robert,
I have up and running 2017.04.02_Dexter_Industries_jessie.img, and have ran Test and Troubleshoot and have attached it. With no sensors etc plugged in.
log.txt (5.8 KB)

I notice that the image uses an older version of raspi_config, will this get updated when I run
DI Software Update, later…

should I re-flash the GrovePi ?

mean while I will run the analog sensors on there own to see what happens


#15

Hi @whimickrh,

I’m looking at the log.txt file and I see everything it’s up and running.


You shouldn’t reflash the GrovePi.
Taking a look in the log.txt file confirms us the GrovePi is reachable.


I’m waiting to see how your analog sensors work.

Thank you!


#16

Hi Robert,

I have run my version of grove_analog_read.py during the afternoon and so far there were no error.
At about 6pm I ran the update programme found on the desktop, rebooted and re-run grove_analog_read.py, and so far witout any errors.

I will leave it running over night and let you the results in the morning.

Many Thanks Michaelgrove_analog_read.py (2.2 KB)


#17

Hi Robert,

Still running OK

Michael


#18

Hi @whimickrh,

It’s great to hear your program works.

I’m closing this topic and I’ll mark it as solved.

Thank you!


#19

This topic was automatically closed after 92 minutes. New replies are no longer allowed.