From: Antonio Ospite Date: Wed, 30 May 2018 14:24:43 +0000 (+0200) Subject: Initial import X-Git-Url: https://git.ao2.it/experiments/Hall_effect_rotary_encoder.git/commitdiff_plain Initial import --- 459a44ca0247324d50b5ca9298c611627d2303c7 diff --git a/Fritzing/Hall-Effect-Sensor.fzz b/Fritzing/Hall-Effect-Sensor.fzz new file mode 100644 index 0000000..57ba1d3 Binary files /dev/null and b/Fritzing/Hall-Effect-Sensor.fzz differ diff --git a/Fritzing/parts/US1881UA_3394d811b1e61364d06f034ffbe599db_6.fzp b/Fritzing/parts/US1881UA_3394d811b1e61364d06f034ffbe599db_6.fzp new file mode 100644 index 0000000..b68a8f3 --- /dev/null +++ b/Fritzing/parts/US1881UA_3394d811b1e61364d06f034ffbe599db_6.fzp @@ -0,0 +1,101 @@ + + + 4 + Antonio Ospite + US1881 Hall effect sensor + + mar mag 29 2018 + + sensor + + + Variant 1 + Sensor + US1881 + + 100mil + + false + THT + + 3 + Single Row + + part.mystery.magical.3.pins + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + + + + + + + + + + + + + + + + + + + + Supply Voltage pin + + +

+ + +

+ + +

+

+ + + + + Ground pin + + +

+ + +

+ + +

+

+ + + + + Output pin + + +

+ + +

+ + +

+

+ + + + + diff --git a/Fritzing/svg/US1881_PCB.svg b/Fritzing/svg/US1881_PCB.svg new file mode 100644 index 0000000..c293c75 --- /dev/null +++ b/Fritzing/svg/US1881_PCB.svg @@ -0,0 +1,189 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Fritzing/svg/US1881_breadboard.svg b/Fritzing/svg/US1881_breadboard.svg new file mode 100644 index 0000000..6b4c82c --- /dev/null +++ b/Fritzing/svg/US1881_breadboard.svg @@ -0,0 +1,122 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + mystery_part_3_sip_100mil_bread.svg + + + + + + + + + + + + + diff --git a/Fritzing/svg/US1881_schematic.svg b/Fritzing/svg/US1881_schematic.svg new file mode 100644 index 0000000..74ed33e --- /dev/null +++ b/Fritzing/svg/US1881_schematic.svg @@ -0,0 +1,134 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + VDD + + VSS + + + OUT + + diff --git a/Tetramag-ring-magnet.svg b/Tetramag-ring-magnet.svg new file mode 100644 index 0000000..2006099 --- /dev/null +++ b/Tetramag-ring-magnet.svg @@ -0,0 +1,751 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.25mm + + + + + + + + 5mm + + + + N + S + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4.1mm + + + + + + + diff --git a/rotary_encoder/Makefile b/rotary_encoder/Makefile new file mode 100644 index 0000000..cc24a34 --- /dev/null +++ b/rotary_encoder/Makefile @@ -0,0 +1,6 @@ +BOARD_TAG = uno +MONITOR_PORT = /dev/ttyACM0 + +ARDUINO_LIBS = DFRkeypad Encoder LiquidCrystal + +include /usr/share/arduino/Arduino.mk diff --git a/rotary_encoder/rotary_encoder.ino b/rotary_encoder/rotary_encoder.ino new file mode 100644 index 0000000..8515524 --- /dev/null +++ b/rotary_encoder/rotary_encoder.ino @@ -0,0 +1,75 @@ +/* + * Rotary encoder example + * + * Copyright (C) 2018 Antonio Ospite + * SPDX-License-Identitier: WTFPL + */ + +#include +#include +#include + +#define ENCODER_CHANNEL_A 2 +#define ENCODER_CHANNEL_B 3 + +#define COUNTS_PER_ROTATION 84 + +#define LCD_RS 8 +#define LCD_EN 9 +#define LCD_D4 4 +#define LCD_D5 5 +#define LCD_D6 6 +#define LCD_D7 7 +#define LCD_BL 10 + +#define BACKLIGHT_VALUE 1023 + +long old_counts = 0; +Encoder encoder(ENCODER_CHANNEL_A, ENCODER_CHANNEL_B); +LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7); + +void setup() { + pinMode(LCD_BL, OUTPUT); + analogWrite(LCD_BL, BACKLIGHT_VALUE); + + lcd.begin(16, 2); + + lcd.setCursor(1, 0); + lcd.print("Rotary Encoder"); + lcd.setCursor(1, 1); + lcd.print("https://ao2.it"); + + DFRkeypad::FastADC(true); + DFRkeypad::iDEFAULT_THRESHOLD=140; +} + +void loop() { + byte key = DFRkeypad::GetKey(); + if (key == DFRkeypad::eSELECT) { + encoder.write(0); + } + + long new_counts = encoder.read(); + if (new_counts != old_counts) { + old_counts = new_counts; + + lcd.clear(); + + lcd.setCursor(0, 0); + lcd.print("Count: "); + lcd.setCursor(8, 0); + lcd.print(new_counts); + + /* Position normalized between 0 and COUNTS_PER_ROTATION */ + long position = ((new_counts % COUNTS_PER_ROTATION) + COUNTS_PER_ROTATION) % COUNTS_PER_ROTATION; + + float angle = position * (360.0 / COUNTS_PER_ROTATION); + + lcd.setCursor(0, 1); + lcd.print("Angle: "); + lcd.setCursor(8, 1); + lcd.print(angle); + } + + delay(20); +} diff --git a/show_quadrature_states/Makefile b/show_quadrature_states/Makefile new file mode 100644 index 0000000..7b0316f --- /dev/null +++ b/show_quadrature_states/Makefile @@ -0,0 +1,6 @@ +BOARD_TAG = uno +MONITOR_PORT = /dev/ttyACM0 + +ARDUINO_LIBS = Encoder + +include /usr/share/arduino/Arduino.mk diff --git a/show_quadrature_states/show_quadrature_states.ino b/show_quadrature_states/show_quadrature_states.ino new file mode 100644 index 0000000..b44f0ad --- /dev/null +++ b/show_quadrature_states/show_quadrature_states.ino @@ -0,0 +1,44 @@ +/* + * Show quadrature states of two Hall effect sensors. + * + * Copyright (C) 2018 Antonio Ospite + * SPDX-License-Identitier: WTFPL + */ + +#define HALL_CHANNEL_A 2 +#define HALL_CHANNEL_B 3 +#define LED_PIN 13 + +int hall_state_A = 0; +int hall_state_B = 0; + +int old_hall_state_A = -1; +int old_hall_state_B = -1; + +void setup() +{ + pinMode(HALL_CHANNEL_A, INPUT); + pinMode(HALL_CHANNEL_B, INPUT); + pinMode(LED_PIN, OUTPUT); + Serial.begin(115200); +} + +void loop() +{ + hall_state_A = digitalRead(HALL_CHANNEL_A); + hall_state_B = digitalRead(HALL_CHANNEL_B); + + if (hall_state_A != old_hall_state_A || + hall_state_B != old_hall_state_B) + { + digitalWrite(LED_PIN, hall_state_A); + + old_hall_state_A = hall_state_A; + old_hall_state_B = hall_state_B; + + Serial.print(hall_state_A); + Serial.print(" "); + Serial.print(hall_state_B); + Serial.print("\r\n"); + } +}