Giter Site home page Giter Site logo

as5048a_rpi_interface's Introduction

As5048a Magnetic Encoder driver for Raspberry pi

Dependencies

This code depends on the awesome C library Broadcom BCM 2835 which can be found and downloaded from this page. The Installation instructions can also be found on the same page, but for the sake of your laziness, here you go:

# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
tar zxvf bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
./configure
make
sudo make check
sudo make install

Build and run

While compiling you also need to link the bcm2835 library. You also need to link the as5048a_rpi_spi.cpp library to your code.

g++ example.cpp as5048a_rpi_spi.cpp -lbcm2835 -o my_example_runnable

The bcm2835 modules need to be initialized with root access when running :

sudo ./my_example_runnable

API

  • As5048a(int csn, int frequency_divider)

Constructor to initialize the Encoder Object takes two inputs, the SPI Chip select pin on the Rpi (choose between 0 and 1, refer here) and the clock frequency divider for the SPI. The datasheet of the encoder specifies a max clock speed of 10MHz, we try to keep a safe space and use a approx 2Mhz clock speed max, for which the divider is 128. Hence by default use 128 as the clock frequency divider.

  • int Read(int reg_address)

This performs the read operation on the encoder chip, and returns the value of whatever register you pass as a parameter to read. For reading the angle of the magnet, you can pass AS5048_CMD_ANGLE, which is defined as a macro in the header file. This will return the hex value corresponding to the rotation of the magnet, the range of the value is between 0x0000 - 0x3FFF. To get the angle in degrees you can use the func listed next.

  • float Degrees(int hex_value)

This converts the hex_value recieved from the Read operation into Degrees. Currently, the observed Precision is approx up to (+-)0.065 degrees.

That's all folks

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.