-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gustavodev #15
Gustavodev #15
Changes from all commits
06fbe85
0420c96
ae17136
9b10458
81ac2a3
f6ee8bb
2c78dba
fc142f1
d3fe2c3
f37e3c9
0726171
763b1c2
c7be74f
1836745
6131d35
56f9ccc
ba2190b
3052a5e
608a90e
3274b2f
536b950
0dc14f6
b8c01d9
b219ee1
0d109d1
09ea87c
744c18d
f0c2f3d
264bf6a
f2562b2
2a16acf
e3a30e6
e8f750f
1190d6c
d06f215
f6959f4
c6d07b0
1cea8a8
8216b6c
7b6aeca
9bacb0c
f999ccc
dd331b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#include <Adafruit_MMC56x3.h> | ||
/* Assign a unique ID to this sensor at the same time */ | ||
Adafruit_MMC5603 mmc = Adafruit_MMC5603(12345); | ||
|
||
//Assigning pins to variables | ||
int xina = 6; | ||
int xinb = 7; | ||
int yina = 4; | ||
int yinb = 5; | ||
int zina = 2; | ||
int zinb = 3; | ||
int xstat = 0; | ||
int ystat = 0; | ||
int zstat = 0; | ||
int magstat = 0; | ||
|
||
|
||
int incomingByte = 0; // for incoming serial data | ||
|
||
void setup() { | ||
// Setting pins as output. | ||
pinMode(xina, OUTPUT); | ||
pinMode(xinb, OUTPUT); | ||
pinMode(yina, OUTPUT); | ||
pinMode(yinb, OUTPUT); | ||
pinMode(zina, OUTPUT); | ||
pinMode(zinb, OUTPUT); | ||
|
||
//Setting all pins off | ||
digitalWrite(xina,LOW); | ||
digitalWrite(xinb,LOW); | ||
digitalWrite(yina,LOW); | ||
digitalWrite(yinb,LOW); | ||
digitalWrite(zina,LOW); | ||
digitalWrite(zinb,LOW); | ||
|
||
//Baudrate/bytes per second set. | ||
Serial.begin(115200); | ||
|
||
|
||
// Initialise the mag sensor */ | ||
if (mmc.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode | ||
magstat = 1; | ||
//mmc.printSensorDetails(); | ||
} | ||
|
||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
|
||
// reply only when you receive data: | ||
if (Serial.available() > 0) { | ||
// read the incoming byte: | ||
incomingByte = Serial.read(); | ||
|
||
// say what you got: | ||
// Serial.print("I received: "); | ||
// Serial.println(incomingByte, DEC); | ||
} | ||
if (incomingByte != 0){ | ||
//Shutdown | ||
if (incomingByte == 97){ | ||
digitalWrite(xina,LOW); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this and similar situations. I would recommend abstracting this to either a static function or some kind of variable-fed function such as: static void write(const byte[] write_bytestring, byte*& result) {
// Conditionally set bits based on the bytestring here
// load result so we can verify the bits were set
} This can help separate code so it improves readability and leave a hook for unit-testing. |
||
digitalWrite(xinb,LOW); | ||
digitalWrite(yina,LOW); | ||
digitalWrite(yinb,LOW); | ||
digitalWrite(zina,LOW); | ||
digitalWrite(zinb,LOW); | ||
xstat = 0; | ||
ystat = 0; | ||
zstat = 0; | ||
} | ||
//X Bridge Off character: 'b' Not working | ||
if (incomingByte == 'b'){ | ||
digitalWrite(xina,LOW); | ||
digitalWrite(xinb,LOW); | ||
xstat = 0; | ||
} | ||
//Y Bridge Off character: 'c' Not working | ||
if (incomingByte == 'c'){ | ||
digitalWrite(yina,LOW); | ||
digitalWrite(yinb,LOW); | ||
ystat = 0; | ||
} | ||
//Z Bridge Off character: 'd' Not working | ||
if (incomingByte == 'd'){ | ||
digitalWrite(zina,LOW); | ||
digitalWrite(zinb,LOW); | ||
zstat = 0; | ||
} | ||
//H-Bridge Status message | ||
if (incomingByte == 's'){ | ||
Serial.print(xstat); | ||
Serial.print(ystat); | ||
Serial.println(zstat); | ||
} | ||
//mag Status message | ||
if (incomingByte == 'q'){ | ||
Serial.println(magstat); | ||
} | ||
//positive "x" | ||
if (incomingByte == 'x'){ | ||
digitalWrite(xinb,LOW); | ||
digitalWrite(xina,HIGH); | ||
xstat = 1; | ||
} | ||
//negative "X" Not working | ||
if (incomingByte == 'X'){ | ||
digitalWrite(xina,LOW); | ||
digitalWrite(xinb,HIGH); | ||
xstat = 2; | ||
} | ||
//positive "y" | ||
if (incomingByte == 'y'){ | ||
digitalWrite(yinb,LOW); | ||
digitalWrite(yina,HIGH); | ||
ystat = 1; | ||
} | ||
//negative "Y" Not working | ||
if (incomingByte == 'Y'){ | ||
digitalWrite(yina,LOW); | ||
digitalWrite(yinb,HIGH); | ||
ystat = 2; | ||
} | ||
//positive "z" | ||
if (incomingByte == 'z'){ | ||
digitalWrite(zinb,LOW); | ||
digitalWrite(zina,HIGH); | ||
zstat = 1; | ||
} | ||
//negative "Z" Not working | ||
if (incomingByte == 'Z'){ | ||
digitalWrite(zina,LOW); | ||
digitalWrite(zinb,HIGH); | ||
zstat = 2; | ||
} | ||
//mag reading | ||
if (incomingByte == 'm'){ | ||
sensors_event_t event; | ||
mmc.getEvent(&event); | ||
Serial.print(event.magnetic.x); | ||
Serial.print(","); | ||
Serial.print(event.magnetic.y); | ||
Serial.print(","); | ||
Serial.println(event.magnetic.z); | ||
} | ||
//temp reading | ||
if (incomingByte == 't'){ | ||
sensors_event_t event; | ||
mmc.getEvent(&event); | ||
float temp_c = mmc.readTemperature(); | ||
Serial.println(temp_c); | ||
} | ||
//end of loop | ||
incomingByte = 0; | ||
Serial.flush(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,4 +122,9 @@ def poll_data(duration = 10.0, dt = 1.0): | |
time_step.append(time_step[-1] + dt) | ||
# temp_array.append(temperature()) | ||
mag_array.append(cage_controller.magnetometer()) | ||
return time_step, mag_array #temp_array, mag_array | ||
return time_step, mag_array #temp_array, mag_array | ||
|
||
if __name__ == "__main__": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this file intended to be the entry point? If so, why here and not |
||
interface() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While single-char commands are technically fine, it might be helpful to future you, ( as well as any future developers), to actually expand these to human-readable command strings.
This would lend itself to opening up a telnet client to the arduino for manual testing which allows you to develop this apart from the python client.