Skip to content

Commit 4191ec8

Browse files
authored
Merge pull request #2 from Vuurvos1/feat/moduleCode
Feat/module code
2 parents 9b3773f + e6ca467 commit 4191ec8

32 files changed

+173
-62
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# SplitFlap
22

3-
modernized split flap
3+
A modernized split flap display.
4+
5+
<div style="text-align: center;">
6+
7+
![SplitFlap](./assets/splitFlap2.png)
8+
9+
</div>
410

511
#### Characters
612

7-
26 `A B C D E F G H I J K L M N O P Q R S T U V W X Y Z`
8-
10 `1 2 3 4 5 6 7 8 9 0`
9-
10 `? ! & ' - = ; : , .` `@ # $ ^ * % / +`
10-
2 `blank □ full ■ `
13+
26 `A B C D E F G H I J K L M N O P Q R S T U V W X Y Z` \
14+
10 `1 2 3 4 5 6 7 8 9 0` \
15+
2 `blank □ full ■ ` \
16+
14 `? ! + - = * ' : , . @ # % €/$` <!-- & ^ ; --> \
17+
18+
`0 O` and `1 I` can share the same flap
19+
20+
<!-- 26 + 8 + 2 = 36 -->
1121

1222
## Parts
1323

@@ -23,4 +33,4 @@ A4988 Stepper Motor Drivers
2333

2434
### Micro controller
2535

26-
Esp32
36+
Esp32 / Arduino pro micro

assets/splitFlap1.png

348 KB
Loading

assets/splitFlap2.png

256 KB
Loading

barrel/barrel.SLDASM

683 Bytes
Binary file not shown.

barrel/blockingTab.SLDPRT

-46.9 KB
Binary file not shown.

barrel/circleMount.SLDPRT

11.3 KB
Binary file not shown.

barrel/circleOpen.SLDPRT

11.5 KB
Binary file not shown.

barrel/flapStopper.SLDPRT

37.2 KB
Binary file not shown.

barrel/motorBackSpacer.SLDPRT

1.1 KB
Binary file not shown.

barrel/motorConnector.SLDPRT

-113 KB
Binary file not shown.

barrel/motorConnectorThicc.SLDPRT

-138 KB
Binary file not shown.

barrel/motorMount.SLDPRT

-111 KB
Binary file not shown.

barrel/motorSpacer.SLDPRT

-48.5 KB
Binary file not shown.

barrel/motorSpacerRound.SLDPRT

-36.1 KB
Binary file not shown.

barrel/spacerBig.SLDPRT

-62 KB
Binary file not shown.

barrel/spacerBigSlot.SLDPRT

-54.9 KB
Binary file not shown.

barrel/spacerSmall.SLDPRT

-47 KB
Binary file not shown.

body/front.SLDPRT

-55.5 KB
Binary file not shown.

body/lager.SLDPRT

-55.7 KB
Binary file not shown.

body/screwFront.SLDPRT

51 Bytes
Binary file not shown.

body/sideLeft.SLDPRT

16.8 KB
Binary file not shown.

body/sideMinimal.SLDPRT

-118 KB
Binary file not shown.

body/sideMount.SLDPRT

-52.5 KB
Binary file not shown.

body/sideRight.SLDPRT

88.3 KB
Binary file not shown.

body/uniBody.SLDPRT

-105 KB
Binary file not shown.

card.SLDPRT

-42.1 KB
Binary file not shown.

code/module/src/main.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
#define RXD1 21
88

99
// defines pins
10-
#define STEP_PIN 13
11-
#define DIR_PIN 12
10+
#define STEP_PIN 22
11+
#define DIR_PIN 23
12+
#define HALL_PIN 15
1213

13-
SplitFlap splitFlap(STEP_PIN, DIR_PIN);
14+
SplitFlap splitFlap(STEP_PIN, DIR_PIN, HALL_PIN);
1415

1516
// Use Serial1 for UART communication
1617
HardwareSerial mySerial(2);
1718

18-
SplitFlap splitFlap(13, 12);
19-
2019
bool readingPacket = false;
2120

2221
void handleMyByte(uint8_t byte)
@@ -31,14 +30,30 @@ void setup()
3130
mySerial.begin(9600, SERIAL_8N1, RXD1, TXD1); // UART setup
3231

3332
splitFlap.init();
33+
splitFlap.home();
3434

3535
Serial.println("Module started");
3636
}
3737

38+
uint8_t flapIndex = 40;
39+
3840
void loop()
3941
{
4042
splitFlap.update();
4143

44+
// move flap every 200ms
45+
static unsigned long lastMove = 0;
46+
if (millis() - lastMove > 5000)
47+
{
48+
flapIndex = (flapIndex + 1) % 50;
49+
50+
Serial.printf("Setting flap to index: %d\n", flapIndex);
51+
splitFlap.setFlap(flapIndex);
52+
// splitFlap.moveFlaps(51); // TODO: make sure this also works with > 50
53+
54+
lastMove = millis();
55+
}
56+
4257
// Check if data is available to read
4358
if (mySerial.available())
4459
{

code/shared/include/SplitFlap.h

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,89 @@
1313
class SplitFlap
1414
{
1515
public:
16-
SplitFlap(int stepPin, int dirPin)
16+
SplitFlap(int stepPin, int dirPin, int hallPin)
1717
{
1818
this->stepPin = stepPin;
1919
this->dirPin = dirPin;
20+
this->hallPin = hallPin;
2021
stepper = AccelStepper(AccelStepper::DRIVER, stepPin, dirPin);
2122

22-
// Set the maximum speed and acceleration
23-
stepper.setMaxSpeed(STEPS_PER_REVOLUTION * 8); // Set the maximum speed in steps per second
24-
stepper.setAcceleration(STEPS_PER_REVOLUTION); // Set the acceleration in steps per second squared
23+
stepper.setMaxSpeed(STEPS_PER_REVOLUTION * 2);
24+
stepper.setAcceleration(STEPS_PER_REVOLUTION * 2);
2525
}
2626

2727
void init()
2828
{
2929
pinMode(stepPin, OUTPUT);
3030
pinMode(dirPin, OUTPUT);
31+
pinMode(hallPin, INPUT_PULLUP);
3132

3233
digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction
33-
34-
this->home();
3534
}
3635

3736
void home()
3837
{
39-
// TODO: implement homing sequence
38+
// TODO: make this non blocking by adding module states
39+
Serial.println("Homing");
40+
stepper.setSpeed(1000); // Steps per second
41+
while (digitalRead(hallPin) == HIGH)
42+
{
43+
stepper.runSpeed();
44+
}
45+
stepper.setCurrentPosition(0);
46+
47+
// TODO: add max steps
4048
}
4149

4250
void update()
4351
{
44-
// if (current pos % flapSteps == 0) {
45-
// stepper.stop(); // reset to prevent overflow
46-
// }
52+
// normalized step
53+
uint16_t normalizedStep = stepper.currentPosition() % STEPS_PER_REVOLUTION;
54+
55+
// at first flap, 1 deg
56+
if (normalizedStep == STEPS_PER_REVOLUTION / 360 && digitalRead(hallPin) == HIGH)
57+
{
58+
Serial.println("Missed steps");
59+
60+
// get the target flap index before resetting the position
61+
const uint8_t targetFlapIndex = getTargetFlapIndex();
62+
63+
stepper.setSpeed(1000); // Steps per second
64+
while (digitalRead(hallPin) == HIGH)
65+
{
66+
stepper.runSpeed();
67+
}
68+
69+
// set position to the nearest full rotation (rounded down)
70+
long offset = stepper.currentPosition() % STEPS_PER_REVOLUTION;
71+
stepper.setCurrentPosition(stepper.currentPosition() - offset);
72+
73+
setFlap(targetFlapIndex);
74+
}
4775

4876
stepper.run();
4977
}
5078

79+
[[deprecated("Use setFlap() with numeric index instead")]]
5180
void setCharacter(char c)
5281
{
5382
int targetIndex = getCharacterIndex(c);
5483
setFlap(targetIndex);
5584
}
5685

57-
void setFlap(int index)
86+
/** move to a specific flap index */
87+
void setFlap(uint8_t index)
5888
{
59-
if (index < 0 || index >= FLAP_COUNT)
89+
if (index >= FLAP_COUNT)
6090
{
6191
Serial.printf("Invalid index: %d\n", index);
6292
return;
6393
}
6494

65-
int currentIndex = getFlapIndex();
66-
int currentPosition = stepper.currentPosition();
95+
const uint8_t currentIndex = getCurrentFlapIndex();
96+
const long currentPosition = stepper.currentPosition();
6797

68-
int steps = index - currentIndex;
98+
int16_t steps = index - currentIndex;
6999

70100
if (steps < 0)
71101
{
@@ -75,50 +105,26 @@ class SplitFlap
75105
stepper.moveTo(currentPosition + steps * FLAP_STEPS);
76106
}
77107

78-
void moveFlaps(int steps)
108+
/** move x amount of flaps */
109+
void moveFlaps(long steps)
79110
{
80-
stepper.moveTo(stepper.currentPosition() + steps * FLAP_STEPS);
111+
stepper.moveTo(stepper.targetPosition() + steps * FLAP_STEPS);
81112
}
82113

83114
private:
84115
int stepPin;
85116
int dirPin;
117+
int hallPin;
86118
AccelStepper stepper;
87119

88-
// 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ
89-
// 10 0123456789
90-
// 20 !@#$%^&*()_+{}|:<>?/.,;[]\\=-`~
91-
// 1 █ (full block)
92-
// 1 space
93-
94-
// "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!@#$%^&*()+:/.,=-`\" █
95-
// ",.?!=/-+:$%()"
96-
97-
// ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+{}|:<>?/.,;[]\\=-`~"
98-
//
99-
100-
// const String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!@#$%^&*()+:/.,=-`\" █";
101-
// "+-*!.#%@?,&': █"
102-
// "?!@&()+-%$█*= "
103-
// " █?!@%'+-=.,#:"
104-
105-
// TODO: maybe reuse 0 and o and 1 and i
106-
// const String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!@#$%^&*()+:/.,=-`\" █";
107-
// | is full block
108-
// ?!@-=+&%$#.,:'
120+
[[deprecated("Update character list")]]
121+
const String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-:,.'%$@?!# █";
109122

110-
// "+-*!.#%@?,&': █"
111-
// "?!@&()+-%$█*= "
112-
// " █?!@%'+-=.,#:"
123+
const uint8_t FLAP_COUNT = 50;
124+
const uint16_t FLAP_STEPS = STEPS_PER_REVOLUTION / FLAP_COUNT;
113125

114-
// +-:,.'%$@?!# █
115-
116-
const String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-:,.'%$@?!# |";
117-
// | is full block??
118-
const int FLAP_COUNT = characters.length();
119-
const int FLAP_STEPS = STEPS_PER_REVOLUTION / characters.length();
120-
121-
int getCharacterIndex(char c)
126+
[[deprecated("Use setFlap() with numeric index instead")]]
127+
uint8_t getCharacterIndex(char c)
122128
{
123129
int index = characters.indexOf(toUpperCase(c)); // toupper(c) ??
124130
if (index == -1)
@@ -129,8 +135,15 @@ class SplitFlap
129135
return index;
130136
}
131137

132-
int getFlapIndex()
138+
/** get the current flap index */
139+
uint8_t getCurrentFlapIndex()
133140
{
134141
return stepper.currentPosition() / FLAP_STEPS % FLAP_COUNT;
135142
}
143+
144+
/** get the target flap index */
145+
uint8_t getTargetFlapIndex()
146+
{
147+
return stepper.targetPosition() / FLAP_STEPS % FLAP_COUNT;
148+
}
136149
};

motorMountTest.SLDPRT

-53.8 KB
Binary file not shown.

splitFlap.SLDASM

-676 Bytes
Binary file not shown.

splitFlapUniBody1.SLDASM

-238 KB
Binary file not shown.

splitflap.code-workspace

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,78 @@
1010
"path": "code/module"
1111
}
1212
],
13-
"settings": {}
13+
"settings": {
14+
"files.associations": {
15+
"algorithm": "cpp",
16+
"array": "cpp",
17+
"atomic": "cpp",
18+
"cctype": "cpp",
19+
"chrono": "cpp",
20+
"clocale": "cpp",
21+
"cmath": "cpp",
22+
"condition_variable": "cpp",
23+
"cstdarg": "cpp",
24+
"cstddef": "cpp",
25+
"cstdint": "cpp",
26+
"cstdio": "cpp",
27+
"cstdlib": "cpp",
28+
"cstring": "cpp",
29+
"ctime": "cpp",
30+
"cwchar": "cpp",
31+
"cwctype": "cpp",
32+
"deque": "cpp",
33+
"exception": "cpp",
34+
"fstream": "cpp",
35+
"functional": "cpp",
36+
"initializer_list": "cpp",
37+
"ios": "cpp",
38+
"iosfwd": "cpp",
39+
"istream": "cpp",
40+
"iterator": "cpp",
41+
"limits": "cpp",
42+
"list": "cpp",
43+
"map": "cpp",
44+
"memory": "cpp",
45+
"mutex": "cpp",
46+
"new": "cpp",
47+
"numeric": "cpp",
48+
"optional": "cpp",
49+
"ostream": "cpp",
50+
"queue": "cpp",
51+
"random": "cpp",
52+
"ratio": "cpp",
53+
"shared_mutex": "cpp",
54+
"sstream": "cpp",
55+
"stdexcept": "cpp",
56+
"streambuf": "cpp",
57+
"string": "cpp",
58+
"string_view": "cpp",
59+
"system_error": "cpp",
60+
"thread": "cpp",
61+
"tuple": "cpp",
62+
"type_traits": "cpp",
63+
"typeinfo": "cpp",
64+
"unordered_map": "cpp",
65+
"utility": "cpp",
66+
"vector": "cpp",
67+
"xfacet": "cpp",
68+
"xhash": "cpp",
69+
"xiosbase": "cpp",
70+
"xlocale": "cpp",
71+
"xlocinfo": "cpp",
72+
"xlocnum": "cpp",
73+
"xmemory": "cpp",
74+
"xmemory0": "cpp",
75+
"xstddef": "cpp",
76+
"xstring": "cpp",
77+
"xtr1common": "cpp",
78+
"xtree": "cpp",
79+
"xutility": "cpp",
80+
"*.tcc": "cpp",
81+
"unordered_set": "cpp",
82+
"memory_resource": "cpp",
83+
"iomanip": "cpp",
84+
"cinttypes": "cpp"
85+
}
86+
}
1487
}

0 commit comments

Comments
 (0)