Coder Social home page Coder Social logo

ob-uart's Introduction

ob-uart – integrate UART communication into org documents

Overview

ob-uart is a wrapper around make-serial-process for org babel, providing integration of UART communication into org documents.

Purpose

ob-uart is useful for communication with devices that use a simple, command based interface over UART, such as is often the case in embedded development.

Using ob-uart allows using org-mode to test and document the interface, e.g.:

set_value_portb 3 1
OK
get_adc0_voltage
0.778

Installation

To use ob-uart, add the repository to your load path, load it and add it to org-babel-load-languages.

(add-to-list 'load-path "~/path/to/ob-uart/")
(org-babel-do-load-languages
 'org-babel-load-languages
 '((uart . t)))

Example

ob-uart can also be useful for tools like the Bus Pirate. The following example shows a temperature readout from an SHT21 humidity & temperature sensor.

  • set mode to I²C, 50 kHz
    m 4 2
        
    m 4 2
    I2C (mod spd)=( 0 1 )
    Ready
    I2C>
        
  • enable power supply and pull-up resistors
    WP
        
    WP
    Power supplies ON
    Pull-up resistors ON
    I2C>
        
  • scan for devices
    (1)
        
    (1)
    Searching I2C address space. Found devices at:
    0x80(0x40 W) 0x81(0x40 R)
        

    :

    I2C>
        
  • send command to trigger temperature measurement
    [0x80 0b11110011 %]
        
    [0x80 0b11110011 %]
    I2C START BIT
    WRITE: 0x80 ACK
    WRITE: 0xF3 ACK
    DELAY 1ms
    I2C STOP BIT
    I2C>
        
  • get result data
    [0x81 r:3]
        

    #+RESULTS[43d384c278126101882a82423eae8f83e4e43d62]: sht21_data

    [0x81 r:3]
    I2C START BIT
    WRITE: 0x81 ACK
    READ: 0x64  ACK 0x74  ACK 0xEA
    NACK
    I2C STOP BIT
    I2C>
        
  • calculate temperature
    bytes = [int(x, 16) for x in data.split("\n")[3][5:].split(" ACK ")]
    print("%.1f" % (-46.85 + 175.72 * (bytes[0] * 256 + bytes[1]) / 2**16))
        
    22.1
        

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.