Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
import time import smbus from collections import deque import matplotlib.pyplot as plt BUS=1 ADDR=0x48 REG_CONV=0x00 REG_CONFIG=0x01 bus = smbus.SMBus(BUS) # Continuous, AIN0, PGA ±4.096V, 860 SPS (chip side) config = 0x8000 | 0x4000 | 0x0200 | 0x0000 | 0x00E0 | 0x0003 bus.write_i2c_block_data(ADDR, REG_CONFIG, [(config>>8)&0xFF, config&0xFF]) FS_VOLTS = 4.096 def read_volts(): data = bus.read_i2c_block_data(ADDR, REG_CONV, 2) raw = (data[0]<<8) | data[1] if raw & 0x8000: raw -= 1<<16 return raw * FS_VOLTS / 32768.0 WINDOW_SECONDS = 0.5 ts = deque() vs = deque() plt.ion() fig, ax = plt.subplots() line, = ax.plot([], []) ax.set_title("ADS1115 AIN0 live (real-time window)") ax.set_xlabel("Time (s)") ax.set_ylabel("Volts") ax.set_ylim(-0.5, 3.5) last_draw = time.perf_counter() draw_interval = 1/30 t_start = time.perf_counter() while True: v = read_volts() t = time.perf_counter() - t_start ts.append(t) vs.append(v) # keep only last WINDOW_SECONDS while ts and (ts[-1] - ts[0]) > WINDOW_SECONDS: ts.popleft() vs.popleft() now = time.perf_counter() if now - last_draw >= draw_interval: # x-axis is "time relative to last point" t0 = ts[-1] xs = [ti - t0 for ti in ts] # ends at 0 line.set_data(xs, list(vs)) ax.set_xlim(-WINDOW_SECONDS, 0) fig.canvas.draw_idle() plt.pause(0.001) last_draw = now
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English