AMS_AS5048B Library for magnetic encoder

Hi guys,

I acquired the AMS AS5048B chip and downloaded the library from

I installed the library via the interface with “adding a .ZIP”.

When I open the example for reading a simple angle, I get the following message.
In file included from read_simple_angle.ino:15:0:
C:…\Documents\Arduino\libraries\AMS_AS5048B-master/ams_as5048b.h:51:18: fatal error: Wire.h: No such file or directory
#include <Wire.h>
compilation terminated."

Can you please advise what I need to do to fix it?

Thanks in advance.

Started Arduino 1.6.8, clicked the "Download ZIP" button at Github, installed via Arduino IDE menu, run simple example and no error for the Arduino Uno.

Sketch uses 6,624 bytes (20%) of program storage space. Maximum is 32,256 bytes.
Global variables use 472 bytes (23%) of dynamic memory, leaving 1,576 bytes for local variables. Maximum is 2,048 bytes.

Which Arduino board did you select ?

I took a glance at the code of ams_as5048b.cpp, and it is nice looking code. The person who wrote it knows how to write code.

I used Mega board. Reloaded libraries and at some point IDE advised which libraries will be used and then problem was resolved.

This is a sun tracking unit. I am using the AS5048B sensor mounted on a shaft which is driven by a stepper motor. I put the following test code together and found via a serial print that the angular values differ between “Serial.println(mysensor.angleR(U_DEG, false), DEC);” and assigning the “mysensor.angleR(U_DEG, false)” to a Double variable and then printing it.

Can anyone perhaps advise why the values differ?

#include <Wire.h> // Reference I2C bus library
#include <OneWire.h>
#include <ams_as5048b.h>

#define ONE_WIRE_BUS 4

//unit consts for AMS AS5048B sensor
#define U_RAW 1
#define U_TRN 2
#define U_DEG 3
#define U_RAD 4
#define U_GRAD 5
#define U_MOA 6
#define U_SOA 7
#define U_MILNATO 8
#define U_MILSE 9
#define U_MILRU 10

// Motor variables
int DirPin = 8; // Direction pin asigned to pin 8
int StepPin = 9; // Step pin asigned to pin 9

// Position sensor variables
AMS_AS5048B mysensor;
double EncoderAngle =0;
double deltaAngle = 0;
long steps = 0;

void setup() {
//Start serial
while (!Serial) ; //wait until Serial ready
//init AMS_AS5048B object
//consider the current position as zero

void loop() {

Serial.print("Angle degree : ");
Serial.println(mysensor.angleR(U_DEG, false), DEC);
Serial.print("EncoderAngle: ");
Serial.print("DeltaAngle: ");
Serial.println(mysensor.angleR(U_DEG, false)-EncoderAngle, DEC);
** Serial.print("DeltaAngle: ");**
Serial.println(mysensor.angleR(U_DEG, false)-EncoderAngle);

steps = steps + 10;


void motor_Init() {
pinMode(DirPin, OUTPUT);
pinMode(StepPin, OUTPUT);
Serial.print(“MotorInit complete”);

void MotorCW(long movesteps) // Turns motor clock wise
pinMode(DirPin, OUTPUT); // Set motor pins to output
pinMode(StepPin, OUTPUT);
digitalWrite(DirPin,LOW); // CW Direction
for (long i=0; i<movesteps; i++) {
digitalWrite(StepPin,HIGH); // Send pulse for motor to trigger on
digitalWrite(StepPin,LOW); // Send pulse for motor to trigger off

void getAngle() {
// read sensor to get the encoder angle
EncoderAngle = mysensor.angleR(U_DEG, false);

One degree jitter. It that bad ?

I need to move approximately 0.25 degrees per minute to keep up with the target, so 1 degree is less than desirable.

I think the mysensor.angleR() function returns the raw value from the sensor. You might need to average a few samples, but I'm not sure how the movingAvg functions of that library work.

Tx Koepel, I will give it a try.