Coder Social home page Coder Social logo

pyacaia's Introduction

pyacaia

Python module to interact with Acaia scales (https://acaia.co/collections/coffee-scales) via Bluetooth (BLE).

Note: If you are using the Acaia Lunar 2021 edition, make sure to update the firmware, otherwise the commands will not work (e.g. tare, start timer etc).

This code was inspired by the javascript version available here https://github.com/bpowers/btscale

0. Requirements

Linux, Python (>=2.7 or >=3.5) and bluepy (https://github.com/lucapinello/bluepy) (pygatt >=4.0.3 is also partially supported https://github.com/peplin/pygatt; Pyxis not supported under pygatt)

This package has been tested on a RasperryPI ZeroW with Raspbian GNU/Linux 9 (stretch) and on Ubuntu Linux 20.04, and with the Lunar and Pyxis scales.

1. Install with:

pip install pyacaia

2. Short example

    from pyacaia import AcaiaScale
    
    scale=AcaiaScale(mac='00:1C:97:17:FD:97')
    
    scale.auto_connect() #to pick the first available
    
    # Or if you know the address use:
    # scale.connect()
    
    # battery value in percent
    print(scale.battery)

    # scale units is 'grams' or 'ounces'
    print(scale.units)

    # minutes of idle before auto-off
    print(scale.auto_off)

    # will the scale beep when a button is pressed?
    if scale.beep_on:
	print('It beeps!')
    else:
	print('It is silent!')

    # is the timer running?
    if scale.timer_running:
	print('timer is running')
	# elapsed time is in seconds, if timer is paused
	# the value will be the displayed time
	# Due to bluetooth transit time, the value
	# may be slightly different than displayed
        print('elapsed time:',scale.get_elapsed_time())

    # Tare the scale
    scale.tare()

    # Control the timer
    scale.startTimer()
    time.sleep(2)
    scale.stopTimer()
    scale.resetTimer()

    #read and print the weight every 0.5 sec for 5 sec 
    for i in range(10):
        print scale.weight # this is the property we can use to read the weigth in realtime
        time.sleep(0.5)
	# check if the scale is still connected, perhaps it was turned off?
	if not scale.connected:
	    break

    scale.disconnect()

Pyacaia now calls bluepy's Peripheral.waitForNotifications() internally. If your application uses waitForNotications() directly with 0.3.0 or earlier, that call should be removed.

By default the backend used is bluepy, but also pygatt is supported. In that case use:

scale=AcaiaScale(mac='00:1C:97:17:FD:97',backend='pygatt')

3. Other functions that may be helpful

Find and list all the acaia scales that are on and in range

addresses=find_acaia_devices()

Print BLE charachteristic of the first available acaia in the list of addresses

if addresses:
        print_acaia_characteristics(addresses[0])
    else:
        print 'No Acaia devices found'

pyacaia's People

Contributors

lucapinello avatar danbodoh avatar nnhjjjjhjhj avatar vctrd avatar lukni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.