Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Temperature Sensor

 

Using the io16 and temperature bricklet along with with a master brick from Tinkerforge, I have created a simple temperature sensor project which outputs its' readings to LEDs on a breadboard. The red LED lights up during warmer temperatures and the yellow LED lights up during cooler temperatures.

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-  
# Temperature Sensor using IO16 and Temperature bricklets

import os

HOST = "localhost"
PORT = 4223
UID = "xXx" # Change to your UID for IO16 bricklet
UID2 = "xXx" # Change to your UID for Temperature bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_io16 import IO16
from tinkerforge.bricklet_temperature import Temperature

ipcon = IPConnection(HOST, PORT) # Create IP connection to brickd
io = IO16(UID) # Create device object
ipcon.add_device(io)

def cb_temperature(temperature):
    running = True
    while running:
        temp = str(temperature/100.0)
        if str(2650) < temp:
            io.set_port_configuration('b', 1 << 0, 'o', False) # Set pin 0 on port b to output low
            io.set_port_configuration('b', 1 << 7, 'o', True) # Set pin 7 on port b to output high
            os.system('clear') # use 'clr' with Windows
            print 'Hot'  # display status
            print (str(temperature/100.0) + ' °C') # get reading
            return
        elif str(2650) > temp:
            io.set_port_configuration('b', 1 << 0, 'o', True) # Set pin 0 on port b to output high
            io.set_port_configuration('b', 1 << 7, 'o', False) # Set pin 7 on port b to output low
            os.system('clear')
            print 'Cold' # display status
            print (str(temperature/100.0) + ' °C') # get reading
            return
        else:
		print 'Reading'
		return

if __name__ == "__main__":

    t = Temperature(UID2) # Create device object
    ipcon.add_device(t) # Add device to IP connection
    # Don't use device before it is added to a connection

    # Set Period for temperature callback to 1s (1000ms)
    # Note: The callback is only called every second if the 
    #       temperature has changed since the last call!
    t.set_temperature_callback_period(1000)

    # Register temperature callback to function cb_temperature
    t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature)

    raw_input('Press key to exit\n') # Use input() in Python 3
    ipcon.destroy()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.