/*send the packet*/
send_result = sendto(s, buffer, ETH_FRAME_LEN, 0,
(struct sockaddr*)&socket_address, sizeof(socket_address));
if (send_result == -1) { errorhandling... }
Example 1.6. Receive a RAW ethernet frame
void* buffer = (void*)malloc(ETH_FRAME_LEN); /*Buffer for ethernet frame*/
int length = 0; /*length of the received frame*/
...
length = recvfrom(s, buffer, ETH_FRAME_LEN, 0, NULL, NULL);
if (length == -1) { errorhandling .... }
* is Unix
Jacob Kaplan-Moss
October 7, 2009
//dirt cheap wireless TX
//generates 38kHz carrier wave on pin 9 and 10
//sends data via TX every 500ms
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
// Clear Timer on Compare Match (CTC) Mode
bitWrite(TCCR1A, WGM10, 0);
bitWrite(TCCR1A, WGM11, 0);
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, WGM13, 0);
// Toggle OC1A and OC1B on Compare Match.
bitWrite(TCCR1A, COM1A0, 1);
bitWrite(TCCR1A, COM1A1, 0);
bitWrite(TCCR1A, COM1B0, 1);
bitWrite(TCCR1A, COM1B1, 0);
// No prescaling
bitWrite(TCCR1B, CS10, 1);
bitWrite(TCCR1B, CS11, 0);
bitWrite(TCCR1B, CS12, 0);
OCR1A = 210;
OCR1B = 210;
Serial.begin(2400);
}
void loop()
{
Serial.println("testing testing testing");
delay(500);
}
void httpRequest()
{
byte theByte;
xPortSerial.print("GET ");
xPortSerial.print(PHP_PAGE_LOCATION);
// value0 = 123 and value1 = 456
// You should change these to be your sensor values or whatever you want to send
// (see php code if you want to add more values or change the names value0/value1
xPortSerial.print("?value0=123&value1=456");
xPortSerial.print(" HTTP/1.1n");
xPortSerial.print(WEB_HOST);
while(!xPortSerial.available()) {} // Just loop until available
theByte = xPortSerial.read();
if (theByte != 0)
Serial.println("Passed.");
else
Serial.println("Failed.");
}
Introducing Bitlash
Bitlash is an open source interpreted language shell for the Arduino serial port. It runs on the Arduino and interprets commands that you type in a terminal window or send programmatically:
bitlash v0.95a here! ... > print "hello, world", analogRead(3) hello, world 552Bitlash is a development and prototyping tool for those situations where you need to bang some bits on the Arduino but writing a sketch in C is premature. The Bitlash command language is very similar to Arduino C and includes a large repertiore of the familiar Arduino C functions so you can hack your hardware from the serial command line or even over the internet via telnet.
void setup(){
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
First, we configure pin 13 for output by setting a bit in Data Direction Register B. Then we turn pin 13 by setting its bit in PORTB. Then we delay 500 milliseconds by marking the current value of timer0, converted into milliseconds, and letting the counter be incremented repeatedly at each clock cycle and overflowed into ever larger holders until the new value of timer0 represents an elapsed time of 500ms. Next we set the bit for pin 13 in PORTB low to turn the LED off. We do the delay dance again and we're home.
For something even smaller, download miniPicoLisp.tgz. It is a minimal version, without support for databases, UTF-8, bignums, IPC, networking and other system-dependent functions. A kind of "pure" Pico Lisp (not "pure Lisp"!). It supports the full Pico Lisp language, but runs faster, and uses even less memory space. It should also not be restricted to Unix. In addition, it compiles and runs also on 64-bit systems.
Jon Kleiser wrote an OpenGL library gl.tgz, and a Chinese Checkers program running on top of it.
Example: sum of first 4 integers.
sum = 0;
for (i = 1; i <= 4; ++i)
sum += i*i;
can be translated to
sum = 0;
i = 1;
loop:
if (i == 5) goto end;;
sum = sum + i;
i = i + 1;
goto loop;
end:
can be translated to
; sum in R16
; i in R17
; R18,R19 used for temporary values
LDI R16, 0
LDI R17, 1
LDI R18, 5
SUB R18, R17
BRBS 1, 22
ADD R16, R17
LDI R19, 1
ADD R17, R19
JMP 2
SLEEP