Chit chat

======

Just a short post this time.

Bought one of those 10 dollar (that was priced at 15 dollars) ethernet boards for the Arduino from Radio Shack. Had the salesperson look up the price. Got it for ten. Took it home and made sure it worked. Since the salesman told me that R/S is pretty much history

More powerful than a 1970’s mainframe.

debiannslu2

—————————————–

QB2C has been around for along time. QB2C is a Quickbasic to C translator. So you can take the Old BASIC source and translate it to C for recompiling. For low end machines such as embedded system this can be a boon for not having to reinvent the wheel. Just put it on my Cisco NSLU2. Of course you have to compile the source code on the unit. That took a while but the working programs seem fast enough. There are some quirks as it is not perfect, so you may have to massage some C code for it to work.

$ cat /proc/cpuinfo
Processor    : XScale-IXP42x Family rev 1 (v5l)
BogoMIPS    : 266.24
Features    : swp half thumb fastmult edsp
CPU implementer    : 0x69
CPU architecture: 5TE
CPU variant    : 0x0
CPU part    : 0x41f
CPU revision    : 1

Hardware    : Linksys NSLU2

But there can be some other advantages. One such advantage is that you can learn C code by comparing the original BASIC code to the resulting C code. Take for example your traditional helloworld program and compare it to the resulting C code.

PRINT “Hello, World!”

$ ./qb2c test.bas test.c
qb2c: translating  test.bas  –>  test.c
Translation done in 0 sec.
$  cat test.c
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <ctype.h>

/* This file was generated by QuickBasic to C translator */
/* qb2c  ver.3.2k 29.Mar.1999 Free version.                            */

#define LMAX 1024

/* Function declarations */

/* Shared variables and arrays declarations */

/* Open files pointers */
main()
{
printf(“%s\n”,”Hello, World!”);
} /* End of MAIN */

Despite the extra code:

PRINT “Hello, World!”

Translates to:

printf(“%s\n”,”Hello, World!”);

Some ways a lot a like.

If we wanted to do a loop then it might turn out like this: (only showing the relevant parts).

From:

FOR X = 1 TO 5
PRINT “Helllo, world!”
NEXT X

to:

static float X;

for(X = 1; X <= 5; X++)
{
printf(“%s\n”,”Hello, world!”);
}

Think you get the idea!

—————————————–

For micro speakers:

—————————————–

One of the first uses of computers was to encode messages such as with the enigma. Also used was the Navajo indian codetalkers to naturally send and receive messages so that the enemy could not decipher them. Even kids have used pig-latin to send secret messages. You do not have to get that compilcated though. Do not know morse code, then let the computer do the translation for you. You could use a program like codeit.

and then go to the morse code option:

If you have source file named test with:

This is a test.

Then the conversion to test.out might be:

–  ….  ..  …   ..  …   .-   –  .  …  –  .-.-.-

One thing to notice is that there is not differentiation between upper and lower case letters.  To do a program like this, you will want to set up a translation table. In fact, you could use any set of characters for your own secret code.

SELECT CASE UCASE$(Character$)

CASE “A”

morsedat$ = “.-”

CASE “B”

morsedat$ = “-…”

CASE “C”

morsedat$ = “-.-.”

CASE “D”

morsedat$ = “-..”

CASE “E”

morsedat$ = “.”

CASE “F”

morsedat$ = “..-.”

CASE “G”

morsedat$ = “–.”

CASE “H”

morsedat$ = “….”

CASE “I”

morsedat$ = “..”

CASE “J”

morsedat$ = “.—”

CASE “K”

morsedat$ = “-.-”

CASE “L”

morsedat$ = “.-..”

CASE “M”

morsedat$ = “–”

CASE “N”

morsedat$ = “-.”

CASE “O”

morsedat$ = “—”

CASE “P”

morsedat$ = “.–.”

CASE “Q”

morsedat$ = “–.-”

CASE “R”

morsedat$ = “.-.”

CASE “S”

morsedat$ = “…”

CASE “T”

morsedat$ = “-”

CASE “U”

morsedat$ = “..-”

CASE “V”

morsedat$ = “…-”

CASE “W”

morsedat$ = “.–”

CASE “X”

morsedat$ = “-..-”

CASE “Y”

morsedat$ = “-.–”

CASE “Z”

morsedat$ = “–..”

CASE “1”

morsedat$ = “.—-”

CASE “2”

morsedat$ = “..—”

CASE “3”

morsedat$ = “…–”

CASE “4”

morsedat$ = “….-”

CASE “5”

morsedat$ = “…..”

CASE “6”

morsedat$ = “-….”

CASE “7”

morsedat$ = “–…”

CASE “8”

morsedat$ = “—..”

CASE “9”

morsedat$ = “—-.”

CASE “0”

morsedat$ = “—–”

CASE “.”

morsedat$ = “.-.-.-”

CASE “?”

morsedat$ = “..–..”

CASE “,”

morsedat$ = “–..–”

CASE “-”

morsedat$ = “-…-”

CASE “/”

morsedat$ = “-..-.”

CASE ” ”

morsedat$ = ” ”

CASE Backspace$, CHR$(29)

morsedat$ = “…-.-”

CASE Escape$

morsedat$ = “.-.-.”

CASE Quote$, CHR$(39)

morsedat$ = “.-..-.”

CASE “:”

morsedat$ = “—…”

CASE “;”

morsedat$ = “-.-.-.”

CASE “(“, “)”

morsedat$ = “-.–.-”

CASE “+”, “&”

morsedat$ = “.-…”

CASE ELSE

morsedat$ = ” ”

END SELECT

If you really wanted to get complicated, you could go through several translations.

—————————————–

If you are a musician, one of the most useful tools is a metronome. It graphically displays the beats for you to follow while playing music.Oneparticular program is all text based so it will tun on a variety of systems even without a sound card. To invoke the program, you use the program name followed by the speed you want to use.

Then the program will start. The program uses a simple cursor to mark the time of the beats.

The program seems to do some compensation to keep the metronome accurate.
To build the program, you would:

$ gcc metronome.c -o metronome

Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>

struct timeval start, last;

inline int64_t tv_to_u(struct timeval s)
{
return s.tv_sec * 1000000 + s.tv_usec;
}

inline struct timeval u_to_tv(int64_t x)
{
struct timeval s;
s.tv_sec = x / 1000000;
s.tv_usec = x % 1000000;
return s;
}

void draw(int dir, int64_t period, int64_t cur, int64_t next)
{
int len = 40 * (next – cur) / period;
int s, i;

if (len > 20) len = 40 – len;
s = 20 + (dir ? len : -len);

printf(“33[H”);
for (i = 0; i <= 40; i++) putchar(i == 20 ? ‘|’: i == s ? ‘#’ : ‘-‘);
}

void beat(int delay)
{
struct timeval tv = start;
int dir = 0;
int64_t d = 0, corr = 0, slp, cur, next = tv_to_u(start) + delay;
int64_t draw_interval = 20000;
printf(“33[H33[J”);
while (1) {
gettimeofday(&tv, 0);
slp = next – tv_to_u(tv) – corr;
usleep(slp);
gettimeofday(&tv, 0);

putchar(7); /* bell */
fflush(stdout);

printf(“33[5;1Hdrift: %d compensate: %d (usec)   “,
(int)d, (int)corr);
dir = !dir;

cur = tv_to_u(tv);
d = cur – next;
corr = (corr + d) / 2;
next += delay;

while (cur + d + draw_interval < next) {
usleep(draw_interval);
gettimeofday(&tv, 0);
cur = tv_to_u(tv);
draw(dir, delay, cur, next);
fflush(stdout);
}
}
}

int main(int c, char**v)
{
int bpm;

if (c < 2 || (bpm = atoi(v[1])) <= 0) bpm = 60;
if (bpm > 600) {
fprintf(stderr, “frequency %d too high\n”, bpm);
exit(1);
}

gettimeofday(&start, 0);
last = start;
beat(60 * 1000000 / bpm);

return 0;
}

Good luck and have fun.

—————————————–

Going to try and experiment to hook a bare arduino to an ethernet board. According to the documentation for the board only six intelligent pins are connected directly. We will see how true that is.

Lines required by the ethernet board. Pins usage on Arduino 

D2 – Connects the INT pin of the W5100
D3 – Contral the reset of the W5100
D10 – Used for SPI Chip Select
D11 – Used for SPI MOSI
D12 – Used for SPI MISO
D13 – Used for SPI SCK

Also see: http://arduino.cc/en/Reference/Ethernet

Screenshot - 11272014 - 11:59:25 PM

SUNP0017

—————————————–

—————————————–

Soda bread

SUNP0004

Good day.

Advertisements