THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time import jetduino from jetduino_pins import * sensor = ARD_A0 jetduino.pinMode(sensor, INPUT_PIN) jetduino.setAnalogReadResolution(10) while True: try: sensor_value = jetduino.analogRead(sensor) #if sensor_value >= 0: print ("sensor_value =", sensor_value) time.sleep(.5) except IOError: print ("Error")
if en_debug: print "Rx:",msg if msg == 'SETUP' : print "Setting up sensors done" elif msg == 'START' : running = True if thread1.is_alive() == False: thread1.start() print "Service Started" elif match_sensors(msg,analog_sensors) >=0: if en_jetduino: s_no=match_sensors(msg,analog_sensors) sens=analog_sensors[s_no] port=int(msg[len(sens):]) a_read=jetduino.analogRead(port) s.sensorupdate({sens:a_read}) if en_debug: print msg print sens +'op:'+ str(a_read) elif msg[:8].lower()=="setInput".lower(): if en_jetduino: port=int(msg[8:]) jetduino.pinMode(port,"INPUT") if en_debug: print msg elif msg[:9].lower()=="setOutput".lower(): if en_jetduino:
api = twitter.Api(consumer_key='YourKey',consumer_secret='YourKey',access_token_key='YourKey',access_token_secret='YourKey') print "Twitter Connected" jetduino.pinMode(led,"OUTPUT") last_sound = 0 while True: # Error handling in case of problems communicating with the GrovePi try: # Get value from temperature sensor [temp,humidity] = jetduino.dht(temperature_sensor,0) t=temp # Get value from light sensor light_intensity = jetduino.analogRead(light_sensor) # Give PWM output to LED jetduino.analogWrite(led,light_intensity/4) # Get sound level sound_level = jetduino.analogRead(sound_sensor) if sound_level > 0: last_sound = sound_level # Post a tweet print ("DI Lab's Temp: %.2f, Light: %d, Sound: %d" %(t,light_intensity/10,last_sound)) api.PostUpdate("DI Lab's Temp: %.2f, Light: %d, Sound: %d" %(t,light_intensity/10,last_sound)) time.sleep(3) except IOError: print "Error"
# Min Typ Max Condition # 0 0 0 sensor in open air # 0 20 300 sensor in dry soil # 300 580 700 sensor in humid soil # 700 940 950 sensor in water # Sensor values observer: # Val Condition # 0 sensor in open air # 18 sensor in dry soil # 425 sensor in humid soil # 690 sensor in water import time import jetduino from jetduino_pins import * # Connect the Grove Moisture Sensor to analog port A0 # SIG,NC,VCC,GND sensor = ARD_A0 while True: try: print (jetduino.analogRead(sensor)) time.sleep(.5) except KeyboardInterrupt: break except IOError: print ("Error")
# I've listed both here: # Specifications # Min Typ Max Click # X 206 516 798 1023 # Y 203 507 797 # My Joystick # Min Typ Max Click # X 253 513 766 1020-1023 # Y 250 505 769 while True: try: # Get X/Y coordinates x = jetduino.analogRead(xPin) y = jetduino.analogRead(yPin) # Calculate X/Y resistance Rx = (float)(1023 - x) * 10 / x Ry = (float)(1023 - y) * 10 / y # Was a click detected on the X axis? click = 1 if x >= 1020 else 0 print ("x =", x, " y =", y, " Rx =", Rx, " Ry =", Ry, " click =", click) time.sleep(.5) except IOError: print ("Error")
def readDigital(): ar0 = jetduino.analogRead(ARD_A0) ar1 = jetduino.analogRead(ARD_A1) ar2 = jetduino.analogRead(ARD_A2) ar3 = jetduino.analogRead(ARD_A3) ar4 = jetduino.analogRead(ARD_A4) ar5 = jetduino.analogRead(ARD_A5) ar6 = jetduino.analogRead(ARD_A6) ar7 = jetduino.analogRead(ARD_A7) ar8 = jetduino.analogRead(ARD_A8) ar9 = jetduino.analogRead(ARD_A9) ar10 = jetduino.analogRead(ARD_A10) ar11 = jetduino.analogRead(ARD_A11) #print("%f, %f, %f, %f, %f, %f" % (ar0, ar1, ar2, ar3, ar4, ar5)) print("%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f" % (ar0, ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9, ar10, ar11)) print("")
import time import jetduino from jetduino_pins import * # The sensitivity can be adjusted by the onboard potentiometer # Connect the Grove HCHO Sensor to analog port A0 # SIG,NC,VCC,GND hcho_sensor = ARD_A0 jetduino.pinMode(hcho_sensor, INPUT_PIN) # Vcc of the grove interface is normally 5v grove_vcc = 5 while True: try: # Get sensor value sensor_value = jetduino.analogRead(hcho_sensor) # Calculate voltage voltage = (float)(sensor_value * grove_vcc / 1024) print ("sensor_value =", sensor_value, " voltage =", voltage) time.sleep(.5) except IOError: print ("Error")
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time import jetduino from jetduino_pins import * # Connect the Grove Loudness Sensor to analog port A0 # SIG,NC,VCC,GND loudness_sensor = ARD_A0 jetduino.pinMode(loudness_sensor, INPUT_PIN) while True: try: # Read the sound level sensor_value = jetduino.analogRead(loudness_sensor) print ("sensor_value =", sensor_value) time.sleep(.5) except IOError: print ("Error")
light_sensor = ARD_A0 # Connect the LED to digital port D4 # SIG,NC,VCC,GND led = ARD_D4 # Turn on LED once sensor exceeds threshold resistance threshold = 10 jetduino.pinMode(led, "OUTPUT") while True: try: # Get sensor value sensor_value = jetduino.analogRead(light_sensor) # Calculate resistance of sensor in K resistance = (float)(1023 - sensor_value) * 10 / sensor_value if resistance > threshold: # Send HIGH to switch on LED jetduino.digitalWrite(led, HIGH) else: # Send LOW to switch off LED jetduino.digitalWrite(led, LOW) print("sensor_value =", sensor_value, " resistance =", resistance) time.sleep(0.5) except IOError:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time import jetduino import atexit atexit.register(jetduino.dust_sensor_dis) jetduino.dust_sensor_en() while True: try: [new_val,lowpulseoccupancy] = jetduino.dustSensorRead() [temp,humidity] = jetduino.dht(4,1) a0 = jetduino.analogRead(0) a1 = jetduino.analogRead(1) a2 = jetduino.analogRead(2) print new_val,lowpulseoccupancy,"temp =", temp, " humidity =", humidity,"a0",a0,"a1",a1,"a2",a2 except: print ("Error")
jetduino.pinMode(led, OUTPUT_PIN) time.sleep(1) # Reference voltage of ADC is 5v adc_ref = 5 # Vcc of the grove interface is normally 5v grove_vcc = 5 # Full value of the rotary angle is 300 degrees, as per it's specs (0 to 300) full_angle = 300 while True: try: # Read sensor value from potentiometer sensor_value = jetduino.analogRead(potentiometer) # Calculate voltage voltage = round((float)(sensor_value) * adc_ref / 1023, 2) # Calculate rotation in degrees (0 to 300) degrees = round((voltage * full_angle) / grove_vcc, 2) # Calculate LED brightess (0 to 255) from degrees (0 to 300) brightness = int(degrees / full_angle * 255) # Give PWM output to LED jetduino.analogWrite(led,brightness) print ("sensor_value =", sensor_value, " voltage =", voltage, " degrees =", degrees, " brightness =", brightness) except KeyboardInterrupt: