Editing
EBB Notes 3
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
I (Rachel) moved the MAXsonar sensor circuit to my own boarduino, successfully. I copied Lamont's shift register/PWM circuit to my own boarduino, again (eventually) successfully. So far this is mere sideways motion... but I have made actual progress in understanding the PWM code, so should soon be able to modify it to include the sensor. Yay tiny progress! Current unsuccessful code that attempts to read the MAXsonar EZ1's serial out: <pre> #include <ctype.h> #define bit9600Delay 84 #define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94 #define PACKET_LENGTH 5 byte rx = 2; byte tx = 3; byte SWval[PACKET_LENGTH]; void setup() { pinMode(rx,INPUT); pinMode(tx,OUTPUT); digitalWrite(tx,HIGH); digitalWrite(13,HIGH); //turn on debugging LED // SWprint('h'); //debugging hello // SWprint('i'); // SWprint(10); //carriage return Serial.begin(9600); } void loop() { Serial.println("begin: "); // wait for the start of a packet int allLow = 1; while(!allLow) { allLow = 1; for(int i = 0; i < 10*10; ++i) { delayMicroseconds(bit9600Delay); if(digitalRead(rx) == HIGH) { allLow = 0; } } } Serial.println("p"); // read a packet for(int i = 0; i < PACKET_LENGTH; ++i) { SWval[i] = SWreadNi(); } Serial.println("r"); // print the packet // TESTING shows that this bit is BROKEN. for(int i = 0; i < PACKET_LENGTH; ++i) { for(int j = 0; j < 8; ++i) { Serial.print( (SWval[i] >> j) & 1 ); } Serial.print(" "); } Serial.println(); Serial.println(); } void SWprint(int data) { byte mask; //startbit digitalWrite(tx,LOW); delayMicroseconds(bit9600Delay); for (mask = 0x01; mask>0; mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx,HIGH); // send 1 } else{ digitalWrite(tx,LOW); // send 0 } delayMicroseconds(bit9600Delay); } //stop bit digitalWrite(tx, HIGH); delayMicroseconds(bit9600Delay); } int SWreadNi() { byte val = 0; while (digitalRead(rx) == LOW); //wait for start bit if (digitalRead(rx) == HIGH) { delayMicroseconds(halfBit9600Delay); for (int offset = 0; offset < 8; offset++) { delayMicroseconds(bit9600Delay); val |= (digitalRead(rx) << offset); } //wait for stop bit + extra // delayMicroseconds(bit9600Delay); // delayMicroseconds(bit9600Delay); return ~val; } } int SWread() { byte val = 0; while (digitalRead(rx)); //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay); for (int offset = 0; offset < 8; offset++) { delayMicroseconds(bit9600Delay); val |= digitalRead(rx) << offset; } //wait for stop bit + extra delayMicroseconds(bit9600Delay); delayMicroseconds(bit9600Delay); return val; } } </pre> [[Category:Sensebridge]]
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information