ublo
bogdan's (micro)blog

bogdan » pic32-pinguino-otg enc28j60 example

11:10 pm on Nov 1, 2012 | read the article | tags:

for a week or so i’m searching the internet for a simple example (that can be easily expanded) on how to use the pic32-pinguino-otg with a UEXT connected enc28j60 module (both from olimex). and of course i didn’t wanted to use the “universal” microchip tcp/ip stack that requires MPlab. after digging quite a lot trough the pinguino repositories, i managed to compile a set of working header files (which you can find here) and a small program from which you can ping your boards. for the library to work, copy it under %pinguino/p32/include/pinguino/libraries/ethernet, where %pinguino is the path to your pinguino installation folder. i used pinguino X.3 and it compiled fine.

/*----------------------------------------------------- 
Author:  --<>
Date: 28/Oct/2012
Description:

-----------------------------------------------------*/
#include <ethernet/ip_arp_udp.h>
#define BUFFER_MAX    224

static u8 buf[BUFFER_MAX+1]; // the received message
u16 len; // the length of the received messages

void setup() {
	// put your setup code here, to run once:
	// this is the enc28j60 ip address
	u8 myip[4] = { 192, 168, 2, 2 };
	// this is the enc28j60 mac address
	u8 mymac[6] = { 0x02, 0x04, 0x08, 0x10, 0x12, 0x14 };
	init_ip_arp_udp (mymac, myip);
	enc28j60Init (mymac);
	}

void loop() {
	len = enc28j60PacketReceive(BUFFER_MAX, buf);
	CDC.printf("received! len: %d\n", len);
    
	if (len == 0) {
		return;
		}
	if(eth_type_is_arp_and_my_ip(buf, len)) {
		make_arp_answer_from_request(buf, len);
		return;
		}
	if(eth_type_is_ip_and_my_ip(buf, len)==0) {
                return;
                }

	if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V) {
		// the ping reply
		make_echo_reply_from_request(buf, len);
		return;
		}
	}

bogdan » motivațional

10:56 pm on Oct 30, 2012 | read the article | tags:

mi-aduc aminte cu plăcere de starea pe care am avut-o la conferința leadership 530°. deși obosit și stresat am reușit să surprind puțin din scânteia pe care participanții au primit-o de la cei trei vorbitori: marian, mircea și bruno. exercițiul pe care vi-l propun – derivat din ceea ce-am prins – este următorul: în fiecare dimineață, imediat după ce te trezești, fixează-ți în minte imaginea celei mai recente realizări încercând să explorezi prin amintiri senzațiile. în același timp ascultă una dintre melodiile de mai jos și strânge cu putere pumnul drept. atunci când vei rămâne fără soluții și moralul nu va depăși nivelul podelei strânge cu putere pumnul și fredonează melodia. efectul e garantat =)

tina turner – simply the best, queen – we are the champions, vangelis – chariots of fire, ennio morricone – ecstasy of gold, survivor – eye of the tiger, bon jovi – it’s my life, turisas – stand up and fight, hans zimmer – arrival to earth, michael jackson – beat it, van halen – jump

bogdan » vreau să-l fac! pot să-l fac! îl fac!

11:45 pm on Oct 26, 2012 | read the article | tags:

nu mă încântă trainingurile sau conferințele motivaționale. deși am furat câteva idei de la prietenii mei traineri, consider că majoritatea cursurilor oferă «easy answers» pe care unii oameni au nevoie să le audă de la cineva cu autoritate.

cu tot scepticismul meu, ieri mi-am schimbat părerea și am văzut ce înseamnă cu adevărat un seminar motivațional.

am dat o mână de ajutor la leadership530° al lui marian și cum sunetul a încăput (ca aproape de fiecare dat?) pe mâna mea, am avut norocul să urmăresc întregul eveniment cu atenție și teamă că ceva nu va merge. energizați de marian, pregătiți de mircea, descompuși și reasamblați de bruno, strigând mantra din titlu, aproape 240 de oameni au trecut cu tălpile goale prin cărbuni proaspăt scoși din foc.

mi-e greu să exprim în cuvinte energia unei mulțimi cu un singur scop: să-și cucerească teama. și nu e nicio «șopârlă» la mijloc: focul e real, arde și e la fel de periculos că orice foc. și totuși, prin spectacolul realizat, participanșii au prins curaj și au trecut peste jar.

sub îndrumarea unui italian nebun, care a știut să facă spectacol de unul singur – folosindu-se de muzică, dansând, combinând stand-up-ul cu discursul motivațional, amestecând hipnoza cu joculețe antrenante – am văzut cum unul câte unul, indiferent de vârstă, au avut curajul să-și învingă teama.

abia acum înțeleg entuziasmul lui cristi popa când îmi povestea cum a trecut prin foc. sincer, experiența merită și sper ca data viitoare să fiu un simplu participant.

bogdan » 5 sfaturi despre cum să-ți asamblezi singur mobila

05:01 pm on Oct 14, 2012 | read the article | tags:

sărind peste context, mi-am luat mobilă pentru dormitor. sursa? www.targuldemobila.ro. nu insist pe detalii, ci pe faptul că a trebuit să-mi asamblez singur un pat, două noptiere, un șifoner cu patru uși și o comodă tv. mai jos 5 sfaturi referitoare la proces:

1. deși în manual scrie că o persoană poate asambla oricare dintre obiectele de mai sus cu o șurubelniță în cruce, un inbus (inclus) și un ciocan, nu recomand pornirea la drum fără o șurubelniță electrică cu doi biți (unul în cruce și un inbus potrivit) și un burghiu de 1.6 sau 2mm.
2. deși în manual scrie că pentru unele bucăți ar trebui să folosiși ținte (sunt incluse), recomand achiziționarea unor șuruburi suplimentare pentru a prinde în special spatele șifonerului. în timp țintele tind să alunece și să scape. am avut noroc și în pachetele pe care le-am primit am găsit o mulțime de șuruburi suplimentare.
3. deși în manual nu scrie, acolo unde nu sunt semne pentru ?urub (ex. balamalele ușilor, rotișe pentru deplasare) folosește burghiul de mai sus pentru a crea un canal de ghidaj: previi spargerea materialului iar șurubul va intra mult mai repede la locul lui.
4. deși în manual nu scrie, nu strânge toate șuruburile ”din prima”. mai bine prinde-le pe toate și când obiectul este asamblat, finisează-l prin strângerea tuturor șuruburilor.
5. deși în manual nu scrie, ar fi bine să ștergi toate părțile componente cu solușie pentru mobil? (ex. pronto) înainte de a le asambla.

Alte chestii care-mi vin în minte:

1. pentru protejarea parchetului în timpul deplasării unui corp mai voluminos, folosește un covoraș inserat între acesta și parchet. e mai ușor de deplasat și nu vei zgâria parchetul.
2. încearcă să construiești aproape de locul unde va fi așezat respectivul obiect.
3. ar fi bine să mai fie cineva care să-ți dea o mână de ajutor. nu mă înțelege greșit, poși să le asamblezi singur, însă ar fi puțin mai ușor.
4. pentru rezistență sporită, unele îmbinări ar putea fi unse cu adeziv (aracet). spre exemplu interiorul patului.
5. nu te zgârci la ținte sau șuruburi. dacă nu ai suficiente, cumpără.
6. din balamale poți regla modul în care se închid ușile. au câte două șuruburi. folosește-le.

bogdan » ideas for the modern computer

08:12 am on Oct 1, 2012 | read the article | tags:

modern computer has its roots in scientific computing service ltd, a british company incorporated by leslie comrie in 1937. the company owned thousand of parallel computers scatter across the country, the “processors” being women working in teams and performing steps from complex algorithms, helped by rudimentary mechanical calculators. this model served as inspiration for alan turing‘s ideas.

reference: nature 486, 12 june 2012, pg. 321
photo source: bbc history

bogdan » modern spies don’t use microphones

10:44 pm on Sep 28, 2012 | read the article | tags:

an article for all my paranoid friends and acquaintances.

i love spy movies. i really do. with little to no exception most of them depict the use of “bugs” to spy on a conversation. more, due to our communist legacy, we (romanians) are proficient at spying. romanian “bugs” were generously (re)covered by our media: here, here and here. unfortunately most of these stories are focused on pretty old, flawed technology.

the “bug”, no matter how small and miniaturized, has a built in weakness: it has to send the information collected to the listener and the preferred medium is modulating an electromagnetic field and actively transport it. needless to say that power sources are involved requiring maintenance.

a better, safer and passive way of spying on other people should start from the definition of a microphone:

microphone: an instrument capable of transforming sound waves into changes in electric currents or voltage, used in recording or transmitting sound.

first, capturing sound is quite easy: the pressure waves travel through an elastic medium bouncing of various surfaces, including windows. the glass is a relatively elastic medium and forced by the sound waves inside – vibrates, transporting inside information to the outside world.

but is there a device capable of measuring the tiny vibration of windows, from a relatively safe distance, in order to recover the leaked information? of course, and it’s around from 1897 when michelson and morley laid the foundation of special theory of relativity: the michelson-morley interferometer. a tool used to measure tiny length variations made by current technologies cheap and suited for spying.

the above picture shows a sketch of the apparatus. any vibration of the movable mirror M1 – actually the spied window – is translated in a variation of the interference pattern, simple enough to be analyzed in real time and converted into sound. using infrared laser diodes (extremely cheap and easy to process with a webcam) you get an invisible, passive, hard to detect “bug”. there are some technical difficulties but any student with basic understanding of the interference process is able to solve them.

my security advice: along with searching for hidden microphones one should be careful talking in a room with outside windows. and no, thermopane® windows are not immune but a thick curtain can greatly improve your privacy.

photo source: here.

bogdan » cheap low power PIR sensor

09:12 pm on Sep 23, 2012 | read the article | tags:

recently i had a problem. i needed to build a wireless PIR sensor that could be powered by a LiPo 1400mAh battery. seems like a lot of juice, but thinking that the wixel draws usually almost 30mA and a mangled PIR sensor 8mA, the sensor would have to be recharged every 1.5 days. not a practical approach. through some neat hack i managed to send the wixel in sleep mode, making it draw less than 100uA, but still had the power hungry PIR sensor.

today i managed to solve this problem also. using a cheap (~$15) PIR sensor with a nice housing and a few components i managed to bring the PIR sensor as low as 1.6mA (measured), making the battery last for 34 days. here’s how:

first remove the PIR element. it’s quite big component, encased in metal and with a window for sensing IR radiation. be careful when removing it as it is quite a sensitive component! then gather the components and build this schematic:

components list:
IS1 is the PIR element. this component was on my Eagle library and matched the dimensions of the one i recovered.
R1, R3 = 47K
R2 = 18K
R4, R8 = 1M
R5 = 1K
R6, R7, R9 = 100K
R10 = 330K
C1, C7 = 10uF (there is no mistake! C7 is 10uF but can be polarized. i used tantalum capacitors)
C2, C3 = 4.7uF
C4, C5, C6 = 10nF
IC1A, IC1B = TL082
JP1 = a 3 pin connector in which 1 = +3V3, 2 = signal (connect to wixel P1_0), 3 = GND
JP2, JP3, JP4 = 2 pin connectors as there’s always a good idea to serve power to other devices

notes:
the R9, R10, C7 group sets the sensitivity of the PIR sensor. this setup worked for what i wanted but trust me, it took about 3 hours of testing to get to those values and configuration. the interrupt on P1_0 of the wixel should be configured for raising edge, not falling. R10 is needed to lower the IC1B output potential below the interrupt threshold. an IR event sends the IC1B output close to 3.3V followed by a drop to almost 0V then back to almost 1.65V (this is the value you should have when idle). with R9/R10 the idle voltage is close to 1.26V making the interrupts stable. setting R10 higher, moves this point close to 1.65V when the interrupts are unstable. making it lower decreases the sensitivity. i don’t recommend getting under 56K (standard value) as the interrupts cannot be triggered anymore.

bibliography:
i drew inspiration from Micropik’s D203B PIR element datasheet.

bogdan » wixel PM3 low power sleep mode (CC2511F32)

10:18 pm on Sep 22, 2012 | read the article | tags:

don’t know if you have any idea what this is, but i love the wixel. it’s a CC2511F32 based device that works basically like every arduino except that it has a embed wireless transceiver. i got mine from watterott. the wixel is a nifty little device, good for connecting sensors to a PC, both wired and wireless. the problem for the wireless approach is that the device is power hungry 30mA is quite a lot for a battery powered app. but luckily, CC2511F32 is made by texas instruments that addressed this issue: it has a sleep mode in which it consumes less than 1uA.

here’s a small code i’ve wrote to test this sleep mode, based on blink led. it blinks the led 10 times, then powers down and waits for a falling edge on P1_0 (remember to connect this pin with a resistor to 3V3 in order to make the device sleep, otherwise P1_0 is quite sensitive).

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>

int32 CODE param_blink_period_ms = 500;
int32 CODE param_count = 20; // counting 20 changes of the red led state, then go to sleep
uint32 count = 0; // the actual counter

uint32 lastToggle = 0;

/* catch interrupts on P1INT					*/
ISR (P1INT, 0) {
	/* clearing the CPU interrupt registers			*/
	/* 1. first the general interrupt register, IRCON2	*/
	IRCON2 &= ~0x08;				// clear IRCON2.P1IF
	/* 2. followed by the P1 interrupt register, P1IFG	*/
	P1IFG &= ~0x01;					// clear P1IF0
	/* not related to the interrupt itself, but to the	*/
	/* sleep mode: clear SLEEP.MODE flag			*/
	SLEEP &= ~0x03;					// clear SLEEP.MODE
	/* disable interrupt only for P1_0			*/
	P1IEN &= ~0x01;					// clear P1_0IEN
	/* wait, disabling interrupts on P1 also :)		*/
	IEN2 &= ~0x10;					// clear IEN2.P1IE
	}

/* the function that puts the system to sleep			*/
/* i've chosen PM3 as i don't need a timer wake-up event	*/
void putToSleep () {
	/* make the P1_0 a input pin				*/
	P1DIR &= ~0x01;					// P1_0DIR = 0 -> input
	/* clear any interrupt flags. see above for details	*/
	IRCON2 &= ~0x08;				// clear IRCON2.P1IF
	P1IFG &= ~0x01;					// clear P1IF0
	/* set the interrupt enable flag on P1_0		*/
	P1IEN |= 0x01;					// P1_0IEN = 1;
	/* set the type of interrupt: 0=rising edge; 1=falling	*/
	PICTL &= ~0x02;					// PICTL.P1ICON = 0
	/* set the interrupt enable flag for the entire P1	*/
	IEN2 |= 0x10;					// IEN2.P1IE = 1;
	/* enable global interrupts				*/
	IEN0 |= 0x80;					// IEN0.EA = 1;
	/* the sleep mode i've chosen is PM3			*/
	SLEEP |= 0x03;					// SLEEP.MODE = PM3
	/* idling the CPU - required in the manual		*/
	if (SLEEP & 0x03) PCON |= 0x01;	// PCON.IDLE = 1;
	}

void updateLeds()
{
    usbShowStatusWithGreenLed();

    LED_YELLOW(0);

    if (getMs() - lastToggle >= param_blink_period_ms/2)
    {
        LED_RED(!LED_RED_STATE);
        lastToggle = getMs();
		/* the piece of code that counts and if the counter	*/
		/* hits the limit, puts the system to sleep		*/
		count++;
		if (count == param_count) {
			count = 0;
			/* here the blinking freezes, waiting for a	*/
			/* falling edge on P1_0				*/
			putToSleep();
			}
    }
}

void main()
{
    systemInit();
    usbInit();
	
    while(1)
    {
        boardService();
        updateLeds();
        usbComService();
    }
}

bogdan » webstock 2012

09:22 pm on Sep 18, 2012 | read the article | tags:

pentru prima dată voi participa la un eveniment dedicat online-ului. webstock 2012. am primit chiar astăzi invitația de la cristian manafu. m-am înscris din curiozitate și din dorința de a cunoaște (cu puțin noroc) personal oamenii ale căror gânduri le citesc în fiecare dimineață. revin cu detalii.

bogdan » viteza sunetului în vid (sic)

08:26 am on Sep 17, 2012 | read the article | tags:

mi-am adus aminte de o afirmație prezentată ca «Fact» în numărul din august al «Știință și Tehnică»:

Viteza sunetului în vid este de aproximativ 1100 km/h.
(S&T / august 2012 / pg. 12)

chiar și cea mai atehnică persoană, cu acces la DEX și noțiuni elementare de logică își poate da seama de inepția unei astfel de afirmații:

SÚNET, sunete, s. n. 1. Vibrație a particulelor unui mediu elastic care poate fi înregistrată de ureche.
VID, -Ă, vizi, vide, adj., s. n. 1. Adj. (Despre un spațiu) Care nu conține nimic; care nu conține aer sau alt gaz; care nu este ocupat, locuit; pustiu.
(DEX’98)

altfel spus, în vid, unde nu există particule care să vibreze, sunetul nu se poate transmite. în articol apare totuși o valoare, 1110 km/h. fiind legat de saltul cu parașuta a lui Felix Baumgartner, de la 29455m, pot să vă spun cu certitudine că viteza respectivă se referă la viteza sunetului la altitudinea de la care s-a realizat saltul, unde încă mai există atmosferă și mediu elastic prin care să se propage unda sonoră.
valoarea corectă variază în funcție de temperatură, între 1062 Km/h (-57°C) și 1083 Km/h (-48°C).

pentru pasionații de calcule, puteți încerca să determinați viteza sunetului folosind formula următoare:
$$v = \sqrt {\gamma \frac {p}{\rho}}$$
unde γ = indexul adiabatic,
p = presiunea atmosferică,
ρ = densitatea aerului;
sursă foto: Smith College

aceast sait folosește cookie-uri pentru a îmbunătăți experiența ta, ca vizitator. în același scop, acest sait utilizează modulul Facebook pentru integrarea cu rețeaua lor socială. poți accesa aici politica mea de confidențialitate.