Code for Ultrasonic ranger sensor using witg Zoul (zolertia2 module)

Grove is a modulated, ready-to-use tool set.
Much like Lego, it takes a building block approach to assembling electronics.

Moderators: lily.li, violet, jeremy882, crail.lyu969

Post Reply
rhinestone.pt
Pre-kindergarten
Pre-kindergarten
Posts: 1
Joined: Sat Jul 13, 2019 5:26 am

Code for Ultrasonic ranger sensor using witg Zoul (zolertia2 module)

Post by rhinestone.pt » Sat Jul 13, 2019 5:36 am

Hey everybody,

I've seen lots of python and cpp codes for ardwino but I need and I'm looking for the code of the grove ultrasonic ranger to use with zolertia2 remote (on contiki OS).

Really appreciated

bill.yu
Junior-7
Junior-7
Posts: 732
Joined: Mon Apr 02, 2018 11:05 am

Re: Code for Ultrasonic ranger sensor using witg Zoul (zolertia2 module)

Post by bill.yu » Wed Jul 24, 2019 3:41 pm

Hi there~

We do not have the zolertia2 modules. you can base on below arduino code to write your own code. The distance equals duration/58. Duration is the ultrasonic trig to echo time travel slot and unit is uS. The distance unit is cm. thanks.

Code: Select all

long Ultrasonic::MeasureInCentimeters(void)
{
	pinMode(_pin, OUTPUT);
	digitalWrite(_pin, LOW);
	delayMicroseconds(2);
	digitalWrite(_pin, HIGH);
	delayMicroseconds(5);
	digitalWrite(_pin,LOW);
	pinMode(_pin,INPUT);
	long duration;
	duration = pulseIn(_pin,HIGH);
	long RangeInCentimeters;
	RangeInCentimeters = duration/29/2;
	return RangeInCentimeters;
}

Post Reply