Skip to content

Commit

Permalink
adds support for G370PDG0, G370PDT0
Browse files Browse the repository at this point in the history
- simplify, reduce su_library_test_example
- change pin assignment on DRDY, RST#
- clang-formatted
- bugfix DLTA_SF, DLTV_SF for G364PDC0
- add ADDR_ID checking and model mismatch detection during device init
  • Loading branch information
cubicleguy committed Aug 23, 2023
1 parent a83c0f5 commit dae7692
Show file tree
Hide file tree
Showing 13 changed files with 2,985 additions and 2,616 deletions.
77 changes: 47 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Epson Sensing Unit (IMU or Accelerometer) UART Driver for Arduino
---------------

______________________________________________________________________

This is an example test library for the Epson M-Gxxx/M-A352
Sensing Units (SU) using the UART interface.
It was specifically developed for use with the Arduino Teensy 3.6
development board (Teensyduino) and includes example applications that
Sensing Units (SU) using the UART interface.
It was specifically developed for use with the Arduino Teensy 3.6
development board (Teensyduino) and includes example applications that
can be used within the Arduino Sketch IDE

For detailed information on the Epson Sensing Units, refer to the datasheet at
Expand All @@ -19,11 +20,12 @@ For further information on the Arduino, refer to their website at
This software is released under the BSD license (see license.txt).
All text must be included in any redistribution.


# Hardware Considerations
---------------

______________________________________________________________________

This library assumes that the user has the following:

- Epson M-Gxxx or M-A352
- Arduino Teensy 3.6 (or compatible) development board
- Arduino Sketch IDE software v1.8.1 or greater
Expand All @@ -34,39 +36,45 @@ The default configuration of the driver assumes that the Epson SU is connected t
Additionally, the RESET# and DataReady (optional) is connected to available pins on the Teensy 3.6.
The following table shows the default pin mapping used by the M-Gxxx/M-A352 driver.

Circuit Pinmapping:
Signal | Teensy 3.6 | Arduino Zero | M-Gseries | M-Vseries
--------|-------------|--------------|------------|------------
DRDY: | pin 3 | pin 3 | pin 13 | pin 14 (Optional)
RESET#: | pin 2 | pin 2 | pin 16 | pin 18
TXDO: | pin 1 | pin 1 | pin 9 | pin 10
RXDI: | pin 0 | pin 0 | pin 7 | pin 12
Circuit Pinmapping:

CAUTION: The Epson SU I/O interface is 3.3V CMOS.
Be sure to use only Arduino devices that are 3.3V I/O!
| Signal to Host | Teensy 3.6 | Arduino Zero | M-Gseries | M-Vseries |
| ----------------- | ---------- | ------------ | ------------ | ------------- |
| DRDY (Optional) | pin 3 | pin 3 | pin 13 | pin 14 |
| RESET# | pin 2 | pin 2 | pin 16 | pin 18 |
| TXDO | pin 1 | pin 1 | pin 9 (SIN) | pin 10 (SIN) |
| RXDI | pin 0 | pin 0 | pin 7 (SOUT) | pin 12 (SOUT) |

**CAUTION**: The Epson SU I/O interface is 3.3V CMOS.
Be sure to use only Arduino devices that are 3.3V I/O!

# Installation Instructions
---------------

______________________________________________________________________

To use the Epson SU Arduino driver and examples, the following steps are required.

1. Install Arduino Sketch IDE (if not already installed)
2. Install the Arduino board
3. Install Epson SU Arduino Library and example sketches
4. Use the Sketch IDE to compile example sketches and upload to the Arduino board

## 1. Install Arduino Sketch IDE
-----------------------------

______________________________________________________________________

The Epson SU Arduino driver is designed to work with the Arduino Sketch IDE.
It was developed and tested using Sketch v1.8.1.
Sketch requires a platform running Windows, Mac OS X, or Linux.
If you do not have Sketch installed on your development platform, please visit the Arduino
If you do not have Sketch installed on your development platform, please visit the Arduino
website and download the version of Sketch compatible with your operating system.
Once Sketch is installed on your development platform, proceed to the next step.
For specific requirements and installation instructions, refer to the Arduino website at www.arduino.cc.

## 2. Install the Teensy 3.6 board
---------------------------------

______________________________________________________________________

The default installation of Arduino Sketch may not include support for the Teensy 3.6.
To confirm whether Teensy support is installed click on “Tools->Board->Boards Manager...” on the Sketch menu.

Expand All @@ -75,7 +83,9 @@ package is not installed, install the latest Teensyduino software. Once the Teen
proceed to the next step.

## 3. Install the Arduino SAM boards
---------------------------------

______________________________________________________________________

The default installation of Arduino Sketch may not include support for the Arduino Zero.
To confirm whether Zero support is installed click on “Tools->Board->Boards Manager...” on the Sketch menu.

Expand All @@ -84,15 +94,19 @@ package is not installed, install the latest version that matches your version o
Once the SAM Boards package is installed, proceed to the next step

## 4. Install Epson SU Library and example sketches
------------------------------------------------------

______________________________________________________________________

The Epson SU Arduino driver is available as a .zip archive that includes the driver and a folder of example sketches.
The Sketch IDE can directly import the driver from a .zip file, so on the Sketch manu click on “Sketch->Include Library->Add .ZIP Library...”.
Then select the Epson SU driver package. This will install the driver and examples.
To confirm that the driver is installed, click on “Sketch->Include Library” and look for the “Epson SU...” entry
at the bottom of the list of available libraries.

## 5. Use the Sketch IDE to compile example sketches and upload to the board
-------------------------------------------------------------------------------

______________________________________________________________________

Before compiling the example sketches, set the Board and Port settings in the Sketch IDE.
The Board and Port settings tell the Sketch IDE which Arduino product is being used and how to communicate with it.
To set the Board for Teensy 3.6, click "Tools->Board->Teensy 3.6".
Expand All @@ -102,19 +116,22 @@ The port that the Teensy 3.6 is located on may differ according to the operating
For issues regarding USB port connections, please refer to the Arduino website at www.arduino.cc.

There are x examples sketches:

- su_library_test_example.ino is designed to test the library functions. It will test the functions, report, and then stop executing.
- su_sampling_example.ino is designed to demonstrate how to read the sensor. It will report the current sensor values in a loop.

To open the example sketches click on “File->Examples", find the "Epson SU UART...", and then select one of the example sketches.
Once the example sketch is loaded, it can be compiled and uploaded to the Arduino.
Note that the Upload stage will fail if the Sketch “Board” and “Port” settings are not configured correctly.
If the upload to the Arduino completes successfully, the output from the example sketch can be viewed using
Note that the Upload stage will fail if the Sketch “Board” and “Port” settings are not configured correctly.
If the upload to the Arduino completes successfully, the output from the example sketch can be viewed using
the Serial Monitor available in "Tools->Serial Monitor".

# Change Record:
Date | Ver | Comment
-----------|-------|------------------
2019-02-25 | v1.0 | - Initial release
2021-03-30 | v1.1 | - Unite IMU and Accelerometers under common Sensing Units
2022-07-21 | v1.2 | - Added support to detect corrupt sensor packets and cleanup
2023-01-17 | v1.3 | - Added support G330/G366, and cleanup

| Date | Ver | Comment |
| ---------- | ---- | ------------------------------------------------------------ |
| 2019-02-25 | v1.0 | - Initial release |
| 2021-03-30 | v1.1 | - Unite IMU and Accelerometers under common Sensing Units |
| 2022-07-21 | v1.2 | - Added support to detect corrupt sensor packets and cleanup |
| 2023-01-17 | v1.3 | - Added support G330/G366, and cleanup |
| 2023-08-16 | v1.4 | - Added support G370PDG0, G370PDT0, cleanup, minor fixes |
142 changes: 76 additions & 66 deletions examples/su_library_test_example/su_library_test_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
to the Teensy 3.6 header (hardware). The pins are mapped as shown below.
Circuit Pinmapping:
Arduino DUE Teensy 3.6 M-Gseries M-Vseries
--------------------------------------------------------------
DRDY: pin 6 pin 3 pin 13 pin 14 (* DRDY is optional)
RX1: pin-18 pin 0 pin 7 pin 10
TX1: pin-19 pin 1 pin 9 pin 12
RST#: pin-7 pin 2 pin 16 pin 18
Host Signal Arduino DUE Teensy3.6 M-Gseries M-Vseries
--------------------------------------------------------------------
DRDY(optional)pin 6 pin 3 pin 13 pin 14
RST# pin-7 pin 2 pin 16 pin 18
TXO pin-19 pin 1 pin 9 (SIN) pin 12 (SIN)
RXI pin-18 pin 0 pin 7 (SOUT) pin 10 (SOUT)
************************************************************************
Expand Down Expand Up @@ -63,10 +63,11 @@
// Epson UART Device Arduino Library Definitions
#include <uart_epson_common.h>

// Assign DataReady is optional, If DRDY not used set to -1 , Otherwise set to assigned pin
// Assign RESET to pin on Arduino
const int8_t EPSON_DRDY = -1; // 3;
const int8_t EPSON_RESET = 2; //Teensy pin 2
// Assign DataReady is optional, If DRDY not used set to -1 , Otherwise set to
// assigned pin Assign RESET to pin on Arduino
const int8_t EPSON_DRDY = -1;
// const int8_t EPSON_DRDY = 6; //Teensy 3.6 pin 6
const int8_t EPSON_RESET = 7; // Teensy 3.6 pin 7

EPSON_DEV su(EPSON_RESET, EPSON_DRDY);

Expand All @@ -75,119 +76,128 @@ EPSON_DEV su(EPSON_RESET, EPSON_DRDY);
*
*------------------------------------------------------------------------------*/
void setup() {
SerialConsole.begin(250000); // Setup Serial communications for 250000bps
SerialConsole.begin(250000); // Setup Serial communications for 250000bps
while (!SerialConsole) {
; // Wait for serial port to connect. Needed for native USB port only
; // Wait for serial port to connect. Needed for native USB port only
}

if (!su.begin()){
SerialConsole.println("Error. Can not communicate properly with " EPSON_UNIT_TYPE);
while (1);
if (!su.begin()) {
SerialConsole.println(
"Error. Can not communicate properly with " EPSON_UNIT_TYPE);
while (1)
;
}

// Toggle SU Reset Line & wait for reset delay time
su.sensorHWReset();

// Initialize SU with settings
if (!su.sensorInit(CMD_RATEX, CMD_FILTERX)) {
SerialConsole.println("Error. Can not initialize " EPSON_UNIT_TYPE);
while (1)
;
}
SerialConsole.println(EPSON_UNIT_TYPE " Init Done");
}

/*------------------------------------------------------------------------------
* loop()
*
*------------------------------------------------------------------------------*/
void loop() {
uint16_t readData[64]; // Set array large enough to store sensor read burst
uint32_t sampleCount = 0;
const uint32_t MAXSAMPLE = 10;

su.sensorConfigDump();
su.sensorScaleFactorsPrint();

SerialConsole.print("Selftest Result (0 is pass) = ");
SerialConsole.println(su.sensorSelfTest(), HEX);

SerialConsole.print("Flashtest Result (1 is pass) = ");
SerialConsole.println(su.sensorFlashTest(), HEX);

// Init SU
if (!su.sensorInit(CMD_RATEX, CMD_FILTERX)) {
SerialConsole.println("Error. Cannot initialize " EPSON_UNIT_TYPE);
while (1);
}
SerialConsole.println(EPSON_UNIT_TYPE " Init Done");

// Test Soft Reset
SerialConsole.print("Goto sampling mode");
su.sensorStart();
SerialConsole.println(EPSON_UNIT_TYPE " Start");
delay(1000);

SerialConsole.print("Goto config mode");
su.sensorStop();
SerialConsole.println(EPSON_UNIT_TYPE " Stop");
delay(1000);
SerialConsole.println("Before Soft Reset");
su.registerDump();

SerialConsole.println("\nConfiguation Before Software Reset");
su.sensorConfigDump();
su.sensorReset();
SerialConsole.println("After Soft Reset");
su.registerDump();


SerialConsole.println("Configuration After Software Reset");
su.sensorConfigDump();

// Init SU
SerialConsole.println("Init Device");
if (!su.sensorInit(CMD_RATEX, CMD_FILTERX)) {
SerialConsole.println("Error. Cannot initialize " EPSON_UNIT_TYPE);
while (1);
SerialConsole.println("Error. Can not initialize " EPSON_UNIT_TYPE);
while (1)
;
}
SerialConsole.println(EPSON_UNIT_TYPE " Init Done");
su.sensorConfigDump();
// Test HW Reset
SerialConsole.println("Goto sampling mode");
su.sensorStart();
SerialConsole.println(EPSON_UNIT_TYPE " Start");
delay(1000);
SerialConsole.println("Goto config mode");
su.sensorStop();
SerialConsole.println(EPSON_UNIT_TYPE " Stop");
delay(1000);
SerialConsole.println("Before HW Reset");
su.registerDump();
su.registerDump();

SerialConsole.println("\nHardware Reset");
su.sensorHWReset();
SerialConsole.println("After HW Reset");
su.registerDump();

// Init SU
if (!su.sensorInit(CMD_RATEX, CMD_FILTERX)) {
SerialConsole.println("Error. Cannot initialize " EPSON_UNIT_TYPE);
while (1);
SerialConsole.println("Error. Can not initialize " EPSON_UNIT_TYPE);
while (1)
;
}
SerialConsole.println(EPSON_UNIT_TYPE " Init Done");
}

/*------------------------------------------------------------------------------
* loop()
*
*------------------------------------------------------------------------------*/
void loop() {

uint16_t readData[64]; // Set array large enough to store sensor read burst
uint32_t sampleCount = 0;
const uint32_t MAXSAMPLE = 5;

su.sensorConfigDump();
su.sensorScaleFactorsPrint();
su.sensorHeaderPrint();

// Go to SAMPLING mode
if (!su.sensorStart()) {
SerialConsole.println("Error. Sensor not entering Sampling mode");
while (1);
while (1)
;
}

su.sensorHeaderPrint();

while (1) {
// Burst read one sensor sample set
if (su.sensorReadBurst(readData, 64)) {
// Output formatted to console
su.sensorDataPrint(readData, sampleCount);
}
else {
} else {
SerialConsole.println("#Corrupted data detected.");
}
}
sampleCount++;

// If sampleCount reaches limit stop application
if (sampleCount >= MAXSAMPLE) {
if (!su.sensorStop()) {
SerialConsole.println("Error. Sensor not entering Sampling mode");
while (1);
while (1)
;
}
// Allow time for pending samples to output
delay(500);

// Clear any left over sensor samples
while (SerialEpson.available() > 0) {
SerialEpson.read();
}
SerialConsole.println("Done.");
su.registerDump();
while (1); // Stops further execution
while (1)
; // Stops further execution
}
}
}


Loading

0 comments on commit dae7692

Please sign in to comment.