Communication between 24-bit rotary encoder working with BiSS/SSI and Arduino
In precision measurement, rotary encoders play a crucial role. This article focuses on 24-bit encoders that operate on the BiSS/SSI (Bidirectional Serial Synchronous Interface/Serial Synchronous Interface) protocol, and how these can be effectively interfaced using the Serial Peripheral Interface (SPI) communication method.
Understanding 24-Bit Encoders
The Basics of Rotary Encoders: Rotary encoders are devices that convert the angular position of a shaft into digital output signals. They are fundamental in applications where accurate rotation measurement is essential.
24-Bit Resolution with BiSS/SSI Protocol: A 24-bit encoder provides over 16 million distinct positions per revolution, offering exceptional precision. These encoders are designed to work with the BiSS/SSI protocol, which is highly specialized for encoder communication.
SPI Communication with BiSS/SSI Encoders
When working with the encoder, we tried using SPI communication and it was successful. First, let's get a clear idea about SPI,
The Role of SPI: SPI is a versatile communication protocol used widely in microcontroller applications. Its adaptability allows it to interface effectively with high-resolution encoders.
Hardware Setup
Components
- Arduino Mega 2560 R3. (Amazon)
- 24-bit Rotary Encoder with BiSS-C Interface.
- 2 MAX485 Modules. (Amazon)
- Breadboard. (Amazon)
- Jumper Wires. (Amazon)
- USB Cable for Arduino.
Make the circuit as below,
Software Setup
#include <SPI.h>
// Define the DE pin for the MAX485 module used for Clock line
const int DE_Clock_Pin = 4; // You can choose any available digital pin
void setup() {
SPI.begin(); // Initialize SPI
Serial.begin(9600); // Initialize Serial communication at 9600 baud rate
pinMode(DE_Clock_Pin, OUTPUT); // Set the DE pin as output
digitalWrite(DE_Clock_Pin, HIGH); // Set the DE pin HIGH to enable transmission mode
}
void loop() {
byte buffer[4]; // Buffer to store received data
// Start SPI transaction
SPI.beginTransaction(SPISettings(1400000, MSBFIRST, SPI_MODE0));
// Send dummy bytes and read data
for (int i = 0; i < 4; i++) {
buffer[i] = SPI.transfer(0x00);
}
SPI.endTransaction();
// Process buffer to extract 24-bit data
unsigned long position = ((unsigned long)buffer[1] << 16) | ((unsigned long)buffer[2] << 8) | buffer[3];
// Round the last two digits
position = (round(position / 100.0)) * 100;
// Print the position to the Serial Monitor
Serial.print("Position: ");
Serial.println(position);
delay(1000); // Delay for demonstration purposes
}
Preparing the Arduino IDE
Install Arduino IDE
- If you haven’t already, download and install the Arduino IDE from the official Arduino website.
Open the Arduino IDE
- Launch the program on your computer.
Code Preparation
- Copy the code you provided into a new sketch in the Arduino IDE.
- Ensure the code is correctly formatted and there are no syntax errors.
Uploading the Code
Connect Arduino to Computer
- Use the USB cable to connect your Arduino Mega 2560 R3 to your computer.
Select the Right Board and Port
- In the Arduino IDE, go to Tools > Board and select “Arduino Mega or Mega 2560”.
- Go to Tools > Port and select the port that shows your Arduino.
Upload the Code
- Press the upload button in the Arduino IDE (right arrow icon).
- Wait for the message “Done uploading” in the status bar.
Testing and Calibration
Monitor Output
- Open the Serial Monitor in the Arduino IDE.
- Rotate the encoder and observe the changes in the values displayed.
Contact Protonest for more details.
Protonest specializes in transforming IoT ideas into reality. We offer prototyping services, expertly crafting tailored solutions from concept to completion. Our commitment to detailed process transparency, client collaboration, and comprehensive post-development support ensures that your visionary IoT concepts become tangible, innovative and advanced prototypes.
Our Website: https://www.protonest.co/
If you enjoyed this article and would like to show some support, consider buying me a coffee on Ko-Fi.
Your support not only helps me keep creating content like this but also fuels me! ☕️📚
Thank you for being an amazing reader!
Here’s my Ko-Fi link: https://ko-fi.com/udarakumarasena
Cheers!