Coder Social home page Coder Social logo

teensyloadcell's Introduction

TeensyLoadcell

Direct load cell readout with a Teensy3.2 Arduino controller board.

Purpose of the Library

The MK20DX256 processor of the Teensy 3.2 includes an on chip differential ADC and a 1-64 PGA (programmable gain amplifier). This is pretty much all you need to directly connect a standard load cell without any other hardware and read it out. The image below shows the required wiring for the differential input pair A10/A11.

Overview

The drawn cable colors match the colors of most of the available, cheap load cells. The two capacitors C1 and C2 are not needed but help to reduce the readout noise.

And here a small test setup:

Setup

Basically TeensyLoadcell is just a shallow wrapper around Pedro Villanueva's ADC library (https://github.com/pedvide/ADC). It sets up the ADC and PGA for differential readout and continuously reads out the load cell in the background using the PDB timer. For noise suppression TeensyLoadcell applies a simple exponential smoothing algorithm with adjustable time constant.

Usage

Minimal Example

The following code shows a minimal usage example. It sets up the load cell with default settings, starts the readout and prints averaged values every 100ms.

#include "ADC.h"
#include "TeensyLoadcell.h"
using namespace TeensyLoadcell;

ADC adc;
Loadcell loadcell(adc.adc0);

void setup(){
   loadcell.start();
}

void loop(){
   Serial.println(loadcell.getValue());
   delay(100);
}

Simple Balance

This example shows how to implement a simple balance with TeensyLoadcell. It is not super precise but works nicely.

Here a quick video showing the balance in action:

Watch the video

#include "Arduino.h"
#include "TeensyLoadCell.h"

using namespace TeensyLoadcell;

ADC adc;
Loadcell loadcell(adc.adc0);

void setup()
{
  while (!Serial);
  Serial.println("Enter s to start/stop, t to tare");

  loadcell.setTau(0.2);  // Changes will require about 5tau = 1s to stabilize
  loadcell.c1 = 5.4f;    // Manually calibrated scale factor, c0 will be set by zeroing later

  loadcell.start();
}

bool isRunning = false;
elapsedMillis stopwatch = 0;

void loop()
{
  int c = Serial.read();
  switch (c)
  {
    case 't': // zero the balance
      loadcell.tare();
      break;

    case 's': // start / stop display
      isRunning = !isRunning;
      break;
  }

  if (stopwatch > 250 && isRunning) // display value each 250ms
  {
    Serial.printf("%5.0f\n", loadcell.getValue());
    stopwatch = 0;
  }
}

teensyloadcell's People

Contributors

luni64 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

teensyloadcell's Issues

code gives error please help

Arduino: 1.8.13 (Windows 7), TD: 1.53, Board: "Teensy 3.2 / 3.1, Serial, 72 MHz, Faster, US English"

C:\Users\Emilio\Documents\Arduino\libraries\TeensyLoadcell-master\src\TeensyLoadCell.cpp:4:17: error: operator '==' has no left operand

#if ADC_USE_PGA == 0

             ^

C:\Users\Emilio\Documents\Arduino\libraries\TeensyLoadcell-master\src\TeensyLoadCell.cpp: In member function 'void TeensyLoadcell::Loadcell::start()':

C:\Users\Emilio\Documents\Arduino\libraries\TeensyLoadcell-master\src\TeensyLoadCell.cpp:75:29: error: no matching function for call to 'ADC_Module::enableInterrupts()'

   adc->enableInterrupts();

                         ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\ADC/ADC.h:59:0,

             from C:\Users\Emilio\Documents\Arduino\libraries\TeensyLoadcell-master\src\TeensyLoadcell.h:3,

             from C:\Users\Emilio\Documents\Arduino\libraries\TeensyLoadcell-master\src\TeensyLoadCell.cpp:1:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\ADC/ADC_Module.h:184:10: note: candidate: void ADC_Module::enableInterrupts(void (*)(), uint8_t)

 void enableInterrupts(void (*isr)(void), uint8_t priority = 255);

      ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\ADC/ADC_Module.h:184:10: note: candidate expects 2 arguments, 0 provided

Error compiling for board Teensy 3.2 / 3.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

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.