

Familiarization Question
#1
Posted 06 January 2011 - 02:35 PM

#2
Posted 06 January 2011 - 02:43 PM
Very, very, many, every, very, many, many, much, much
... perhaps not that much. But it *is* that very difference that seperates us (the noble users of netmf) from the
Nah, don't worry. Throw in some code and we can show you some of the differences.
#3
Posted 06 January 2011 - 02:53 PM
+++++ +++++ [ > +++++ ++ > +++++ +++++ > +++ > + <<<< - ] > ++ . > + . +++++ ++ . . +++ . > ++ . << +++++ +++++ +++++ . > . +++ . ----- - . ----- --- . > + . > .
+ counts up, - counts down. < and > shifts the current reg, . outputs a character. It's easy! We got the smallest compiler in the world ^^
#4
Posted 06 January 2011 - 02:59 PM
I have been using a Netduino for 3 or 4 months and I have ported several Arduino projects to the Netduino having never seen an actual Arduino board! (However, I just bought an Arduino UNO a few days ago). The Arduino community is a rich resource of ideas and code and familiarity with both Netduino and Arduino makes for a lot of fun.
- Jan Olof likes this
#5
Posted 06 January 2011 - 03:23 PM
Brainf**k Embedded+ counts up, - counts down. < and > shifts the current reg, . outputs a character. It's easy! We got the smallest compiler in the world ^^

#6
Posted 06 January 2011 - 04:15 PM
public class Program { public static void Main() { //test hello world brainfck program string brainfckProgram = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."; Compilers.Brainfck.Execute(brainfckProgram, 0, brainfckProgram.Length, new Compilers.Brainfck.IOHandler(PutFunction), new Compilers.Brainfck.IOHandler(GetFunction)); } public static void GetFunction(ref byte B) { //don't do anything } public static void PutFunction(ref byte B) { string str = "" + (char)b; Microsoft.SPOT.Debug.Print(str); } }
It will write out on the "Debug", but you can redirect it if you want.
The possibilities are endless! One could put tons of Brainfck code on a SD card and then execute it from there!
w00t

Attached Files
#7
Posted 06 January 2011 - 05:35 PM

#8
Posted 06 January 2011 - 05:57 PM
Great to know guys! Thanks for the promptness of replies LOL I am unfortunately waiting to receive my Netduino
Just covering my bases and getting to know the lay of the land before I dive face first into the unit LOL
Is the SD card just used for code or can it be a pseudo datalogger as well?
Yes, absolutely. Netduino has FAT16/FAT32 file system support. You can create, read, and write files easily...up to 2GB of data.
Chris
#9
Posted 18 January 2011 - 03:34 PM
Ive done the fancy LED blink and Button Press examples and moved on to read from my GPS sensor. Next I will be trying to take that GPS data and write to a file on the SD card but Im pretty unfamiliar with how to go about writing to a file. Is there a tutorial for this? Is it simple/straightforward for a newb to do?
Also Ill be looking to read from a AHRS from CHRobotics, http://www.chrobotic...o&products_id=2 , hopefully this will be a semi straigtforward task as well. Even though all Ive really done with the AHRS is use the software from CHRobotics to view the data. Not really sure how to manually read the data via the Netduino and C# programming. But its all a learning process!
Heres some code I found online for the Arduino but unsure how to start to bring this over to the netduino....
float CHR_yawClean; float CHR_pitchClean; float CHR_rollClean; float CHR_accel_zClean; #define CHR_MESSAGE_LENGTH 16 //in bytes //byte 1 contains 's' //byte 2 contains 'n' //byte 3 contains 'p' //byte 4 contains PT, packet type //byte 5 contains N (the number of data bytes to expect) //FIRST DATA BYTE IS BYTE NUMBER 6 //byte 6 and 7 contains info about active channels //byte 8 and 9 contains YAW //byte 10 and 11 contains PITCH //byte 12 and 13 contains ROLL //byte 14 and 15 contains ACCEL_Z //byte 16 and 17 contains CHK_SUM (N+6/N+7) #define BYTE1 0 #define BYTE2 1 #define BYTE3 2 #define PT_BYTE 3 #define N_BYTE 4 #define DATA_BYTE1 5 #define DATA_BYTE2 6 #define YAW_BYTE1 7 #define YAW_BYTE2 8 #define PITCH_BYTE1 9 #define PITCH_BYTE2 10 #define ROLL_BYTE1 11 #define ROLL_BYTE2 12 #define ACCEL_Z_BYTE1 13 #define ACCEL_Z_BYTE2 14 #define CHK_BYTE1 15 #define CHK_BYTE2 16 #define CHR_YAW_FACTOR 0.0109863F //from datasheet #define CHR_PITCH_FACTOR 0.0109863F #define CHR_ROLL_FACTOR 0.0109863F #define CHR_ACCEL_Z_FACTOR 0.106812F //transmission freq. from CHR6DM: 100Hz (73 in the Broadcast setting) void setup() { Serial.begin(57600); Serial1.begin(115200); } void loop() { readCHR6DM(); Serial.print("Yaw: "); Serial.print(CHR_yawClean); Serial.print(" Pitch: "); Serial.print(CHR_pitchClean); Serial.print(" Roll: "); Serial.print(CHR_rollClean); Serial.print(" Acc_Z: "); Serial.println(CHR_accel_zClean); delay(350); //unit set to 100Hz continous sending } void readCHR6DM() { int CHR_yawWord, CHR_pitchWord, CHR_rollWord, CHR_accel_zWord; unsigned int CHR_checksumWord, calculated_checksumWord; int i, j; unsigned char buffer[CHR_MESSAGE_LENGTH+2]; //17 bytes unsigned long sumOfBytes; //byte 1 contains 's' //byte 2 contains 'n' //byte 3 contains 'p' //byte 4 contains PT, packet type //byte 5 contains N (the number of data bytes to expect) //FIRST DATA BYTE IS BYTE NUMBER 6 //byte 6 and 7 contains info about active channels //byte 8 and 9 contains YAW //byte 10 and 11 contains PITCH //byte 12 and 13 contains ROLL //byte 14 and 15 contains ACCEL_Z //byte 16 and 17 contains CHK_SUM (N+6/N+7) //N is expected to be 10 if (Serial1.available() > 0) { startOfRead: i = 0; buffer[i] = Serial1.read(); if(buffer[i] == 's') { //byte 1 element 0 i++; buffer[i] = Serial1.read(); //Serial.println(buffer[BYTE1]); //debug } else { goto startOfRead; } if(buffer[i] == 'n') { //byte 2 element 1 i++; buffer[i] = Serial1.read(); //byte 3 element 2 //Serial.println(buffer[BYTE2]); //debug } else { goto startOfRead; } if(buffer[i] == 'p') { //byte 3 element 2, begin getting the whole thing because 3 start bytes checked to be valid i++; buffer[i] = Serial1.read(); // byte 4 element 3 (PT_BYTE) //Serial.println(buffer[BYTE3]); //debug } else { goto startOfRead; } if(buffer[i] == 0xB7) { // byte 4 element 3 (PT_BYTE) i++; buffer[i] = Serial1.read(); // byte 5 element 4 (N_BYTE) //Serial.println(buffer[PT_BYTE], HEX); //debug //Serial.println(buffer[N_BYTE], DEC); //debug this is 10 dec! } else { goto startOfRead; } if(buffer[i] == 0x0A) { // byte 5 element 4 (N_BYTE) expect 10 dec checks out! i++; buffer[i] = Serial1.read(); // byte 6 element 5 (DATA_BYTE1) //Serial.println(buffer[DATA_BYTE1], BIN); //debug this prints 1110000 checks out } else { goto startOfRead; } if(buffer[i] == 0xE0) { // byte 6 element 5 (DATA_BYTE1) expect 70 hex this should check out i++; buffer[i] = Serial1.read(); // byte 7 element 6 (DATA_BYTE2) //Serial.println(buffer[DATA_BYTE2], BIN); //debug } else { goto startOfRead; } if(buffer[i] == 0x02) { // byte 7 element 6 (DATA_BYTE2) expect 2 hex i++; buffer[i] = Serial1.read(); //byte 8 element 7 (YAW_BYTE1) i++; buffer[i] = Serial1.read(); //byte 9 element 8 (YAW_BYTE2) i++; buffer[i] = Serial1.read(); //byte 10 element 9 (PITCH_BYTE1) i++; buffer[i] = Serial1.read(); //byte 11 element 10 (PITCH_BYTE2) i++; buffer[i] = Serial1.read(); //byte 12 element 11 (ROLL_BYTE1) i++; buffer[i] = Serial1.read(); //byte 13 element 12 (ROLL_BYTE2) i++; buffer[i] = Serial1.read(); //byte 14 element 13 (ACCEL_Z_BYTE1) i++; buffer[i] = Serial1.read(); //byte 15 element 14 (ACCEL_Z_BYTE2) i++; buffer[i] = Serial1.read(); //byte 16 element 15 (CHK_BYTE1) //Serial.println(buffer[i], DEC); i++; buffer[i] = Serial1.read(); //byte 17 element 16 (CHK_BYTE2) //Serial.println(buffer[i], DEC); } //else { goto startOfRead; } //for(i = 0; i < CHR_MESSAGE_LENGTH; i++){ //we're still at byte 3 element 2, execution gets us to byte 4 element 3 //buffer[i] = Serial1.read(); //first time here i=3 (byte 4), i=4 (byte 5), i=5 (byte 6), i=6, i=7, i=8, i=9, i=10, i=11, i=12, i=13, i=14, i=15, i=16(byte 17), i=17(byte18 nonexistent) //} } else{ Serial.println("Sensor not connected"); } // sumOfBytes = 0; // for(i=-1;i<13;i++) { //ska gå element 0 till 14 // sumOfBytes += buffer[i]; // } // // Serial.print("sumOfBytes: "); // Serial.print(sumOfBytes, DEC); // // CHR_checksumWord = (unsigned)buffer[CHK_BYTE1]<<8; // CHR_checksumWord |= buffer[CHK_BYTE2]; // //CHR_checksumWord = (unsigned long)(buffer[CHK_BYTE1] + buffer[CHK_BYTE2]); // Serial.print(" CHR_checksumWord: "); // Serial.println(CHR_checksumWord, DEC); // //if( ) { //plMSB = Serial1.read(); //plLSB = Serial1.read(); //myInt = (int)plMSB<<8; YÄÄÄÄH! //myInt |= plLSB; CHR_yawWord = (int)buffer[YAW_BYTE1]<<8; CHR_yawWord |= buffer[YAW_BYTE2]; CHR_pitchWord = (int)buffer[PITCH_BYTE1]<<8; CHR_pitchWord |= buffer[PITCH_BYTE2]; CHR_rollWord = (int)buffer[ROLL_BYTE1]<<8; CHR_rollWord |= buffer[ROLL_BYTE2]; CHR_accel_zWord = (int)buffer[ACCEL_Z_BYTE1]<<8; CHR_accel_zWord |= buffer[ACCEL_Z_BYTE2]; CHR_yawClean = (CHR_yawWord * CHR_YAW_FACTOR); CHR_pitchClean = (CHR_pitchWord * CHR_PITCH_FACTOR); CHR_rollClean = (CHR_rollWord * CHR_ROLL_FACTOR); CHR_accel_zClean = (CHR_accel_zWord * CHR_ACCEL_Z_FACTOR); //} }
Any help/ideas will be appreciated.
Thanks
N
#10
Posted 19 January 2011 - 08:52 AM
Despite the fact that netmf is best suited at threading, the above code could run with a few modifications I guess.
Eg.
#define BYTE1 0
is
private const byte BYTE1 = 0;
The Serial.print is used for debug right? In that case it is:
System.Diagnostics.Debug.Print
The Serial1 on the other hand is the uart0 right? So that's a slightly different story. You can search out a lot of serial examples on the this site though.
#11
Posted 19 January 2011 - 12:38 PM
#12
Posted 19 January 2011 - 02:56 PM
int CHRtoRead = serialPort2.BytesToRead; if CHRtoRead >0) { led.Write(true); Thread.Sleep(100); led.Write(false); byte[] buffer = new byte[CHRtoRead]; serialPort2.Read(buffer, 0, buffer.Length); serialPort1.Write(buffer, 0, buffer.Length); }
I do get return data from the AHRS now but its in HEX so I need to convert the HEX values to real numbers. And then pick out the Pitch Roll and Yaw from the data.
#13
Posted 19 January 2011 - 03:07 PM
When I view the data on my serial line in RS232 through a level shifter I get some garbage data. I thought maybe that it was due to the fact I was using the same buffer for GPS and AHRS but even after I changed the code I still get garbage data. See attached code and data sample. Take note the GPS is mix matched because I have to view the data in my terminal window via HEX view so it chops up my GPS data. Eventually I will strip out the data and process it to view numerically rather than in HEX for a uniform data feed.
SerialPort serialPort1 = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One); serialPort1.Open(); SerialPort serialPort2 = new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One); serialPort2.Open(); while (true) { int GPStoRead = serialPort1.BytesToRead; //start reading the stream if (GPStoRead > 0) { //blink the LED to show we got data led.Write(true); Thread.Sleep(100); led.Write(false); // get the waiting data byte[] GPSbuffer = new byte[GPStoRead]; serialPort1.Read(GPSbuffer, 0, GPSbuffer.Length); serialPort1.Write(GPSbuffer, 0, GPSbuffer.Length); //only accept a statement starting with $ if (GPSbuffer[0] != 36) continue; //copy the byte array to a readable string String str = new String(System.Text.Encoding.UTF8.GetChars(GPSbuffer)); //break up string into statements String delimStr = "\r"; char[] delim = delimStr.ToCharArray(); string[] statements = null; statements = str.Split(new Char[] { '\r', '\n' }); for (int i = 0; i < statements.Length; i++) { //only accept statements with a checksum String currStatement = statements[i]; if (currStatement.Length > 0 && currStatement.IndexOf("*") >= 0) parseNMEA(statements[i]); } } //poll every half secondif (GPStoRead > 0) int CHRtoRead = serialPort2.BytesToRead; if (CHRtoRead > 0) { //blink the LED to show we got data led.Write(true); Thread.Sleep(100); led.Write(false); // get the waiting data byte[] CHRbuffer = new byte[CHRtoRead]; serialPort2.Read(CHRbuffer, 0, CHRbuffer.Length); serialPort1.Write(CHRbuffer, 0, CHRbuffer.Length); } Thread.Sleep(1000); } }
Sample Data
24 47 50 47 47 41 2c 31 35 30 36 31 39 2e 32 30 $GPGGA,150619.20
30 2c 34 37 33 35 2e 31 33 30 38 2c 4e 2c 30 35 0,4735.1308,N,05
32 34 34 2e 32 32 36 37 2c 57 2c 31 2c 31 30 2c 244.2267,W,1,10,
30 2e 38 34 2c 31 31 34 2e 36 2c 4d 2c 31 34 2e 0.84,114.6,M,14.
34 2c 4d 2c 2c 2a 37 31 0d 0a 73 6e 70 b7 20 ff 4,M,,*71..snp· ÿ
fe fb 29 01 9e 02 dc 00 03 fe b7 ff a2 00 28 00 þû).ž.Ü..þ·ÿ¢.(.
Questions comments concerns?
Thanks
#14
Posted 20 January 2011 - 03:52 AM
#15
Posted 20 January 2011 - 10:15 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users