abC Project: Arduino, Bluetooth, and Compass V1.0

GY-85 Board, HC-06, Processing 3.1 & Arduino 1.6.12 — arduSerie 24

J3
Jungletronics
5 min readDec 31, 2016

--

Hi Hobbyist,
This is GY-85 Board (9DOF ITG3205 ADXL345 HMC5883L Sensor Breakout).

GY-85
HC-06

We will implement a compass connected to the Arduino via Bluetooth. We used the HC-06 Bluetooth dongle, GY-85 board, which sensors used are only HMC5883L out of three.

GY-85’s sensors are:

  • ADXL345 - 3-axis Accelerometer — 7-bit address (0x53): Post link
  • HMC5883L- 3-axis Magnetometer — 7-bit address (0x1E): This Post
  • ITG3205- 3-axis Gyroscope — 7-bit address (0x68): Soon..
GY-85 Sensors

So, this tutorial deals with :

HMC5883L 3-axis Magnetometer, a 7-bit address (0x1E) plus 1 bit read/writ (identifier by 0x3D for read and 0x3C for write).

#define Magnetometer 0x1E //I2C 7bit address of HMC5883

Our code are result from two other blended ones:

_24_arduSerie_Arduino_Bluetooth.ino — How Bluetooth Work
_24_arduSerie_Arduino_Compass.ino — How Compass Work

Results:

_24_arduSerie_Arduino_Bluetooth_Compass.ino — Final Result

Here is Processing v3.1 code (change for your serial BT port):

_24_Arduino_Compass_BT_Processing.pde

Let’s start from the very simple.
Here is the first one:

We simply open a count on the Arduino terminal. Because the Arduino serial buffer (RX and TX) is being directed to the Bluetooth port just connect to the port on which the Bluetooth is installed and ready. Too simple, right?

Now pay close attention to the secret !!

Connect by cell phone is a piece of cake. I’m using the BluetoothTerminal (
I2C communication to all 3 sensors) downloaded from google play for the test.

Easy, now comes the biggest difficulty, which I make to be simple as well. Look:

Connect the Arduino with the ready protoboard. When charging for the Bluetooth it starts flashing immediately. You are ready to connect. Click Bluetooth Device on your windows 10 work bar, right in the Bluetooth icon, to configure everything. Open configuration, hardware tab to verify that the HC-06 (or whatever name have yours) has been correctly identified. Click the COM ports tab, Add, select output - the initial computer communication, and in the dropbox select your Bluetooth device. Soon it is added. Open Putty and plug in the door you found. Increasing counting should appear and the first step was given... Congratulations. It’s already halfway. Good!!!!

Watch the video to learn this lesson part too. This secret is a piece of the cake anyway, the cat’s leap in this tutorial.

Now let’s go to the main code. How to work with the magnetometer? I borrow the code from Dejan Nedelkovski (awesome hobbyist!!!) see first the whole thing:

Do not panic!!! It’s a little long, but it’s easy !!!
Let’s divide it into 3 parts: Initial settings, setup, and loop, as we are accustomed …

For the x, y, and z axes we have two records for each. We declare constants and variables to save them. We set the address on the i2c bus for the magnetometer: and then put the chip to Select Mode register and Continuous Measurement mode.

A consult to its datasheets helps us a lot and you’d rather do it too, see datasheet ….

In the loop, for each axis we start the transmission, we request the information for each record/axis and we finish the transmission. It stops processing to wait for the answer. We repeat this same procedure for each axis (x,y,z).

At the end we make the necessary calculations to finally show the compass needle rotation and bang that’s it…

Just one more detail: the magnetic north differs from the geographical north. We need to do what is called magnetic declination. You must find the magnetic declination at your location. The code original made 4.2 degrees => 0.073 rad probable from Skopje, Macedonia; mine is -12.44 degrees = > -0.19540706305329 rad… can you guess where I am?

See this link to get your value (http://www.magnetic-declination.com/). Transfer degrees for radians with the help of this page: Unit Juggler.

Now here’s the final code, which is a blend of the previous two.
This is the code that you will run on your Arduino together with the processing code if you will…

_24_arduSerie_Arduino_Bluetooth_Compass.ino — Final Result

Phew, we broke up... Now just learn how to use the compass. A lot of people on the internet wanting to teach us !!!

Thanks,

Happy New 2017 Year to everyone !!!

Bye for now!!!

Comments are welcomed!! You are reading the Jungletronics page!!!

GY-85 Board specifications:

On-board 3.3V Voltage Regulator
Logic Level conversion
Fully compatable with 5V and 3.3V systems
Dimensions: 0.87 in x 0.63 in x 0.12 in (2.2 cm x 1.6 cm x 0.3 cm)
Weight: 1.09 oz (31 g)
9 axis module (three-axis gyro + three axis acceleration + three axial magnetic) containing some of the most popular chips. What also sets this board apart from others is the integrated 3.3V Voltage Regulator and Logic Level Conversion.
You can connect this board directly to 5V systems (5V power in to VCC) and the SDA and SCL pins will be at 5V levels, but you can also connect it directly to 3.3V systems (3.3V power in to VCC) and the SDA and SCL pins will be at 3.3V levels.It combines a SAMD21 microprocessor with an MPU-9250 9DoF (nine degrees of freedom) sensor to create a tiny, re-programmable, multi-purpose inertial measurement unit (IMU). It can be programmed to monitor and log motion, transmit Euler angles over a serial port, or to even act as a step-counting pedometer.It features three, three-axis sensors — an accelerometer, gyroscope, and magnetometer — which gives it the ability to sense linear acceleration, angular rotation velocity, and magnetic field vector’s. The on-board microprocessor — Atmel’s SAMD21G18A — is an Arduino-compatible, 32-bit ARM Cortex-M0+ microcontroller also featured on the Arduino Zero and SAMD21 Mini Breakout boards.

Download All Archives for This Project

References:

ITG-3200

Digital Accelerometer ADXL345

HMC5883L

How To Make a Compass using Arduino and Processing IDE — Dejan Nedelkovski

Tutorial — Using HC06 Bluetooth to Serial Wireless UART Adaptors with Arduino

Cheap 2-Way Bluetooth Connection Between Arduino and PC by techbitar in Arduino

Updated: 10/05/2017 6:21 PM — gist the codes!

Updated: 28/11/2020 — Minors text corrections:)

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!