Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino2 ultrasonic sensor + 8x8 LED matrix + Speaker

Netduino 2 ultrasonic sensor I2C PWM

  • Please log in to reply
3 replies to this topic

#1 Shivaram K R

Shivaram K R

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationIndia

Posted 04 August 2013 - 05:13 PM

I am sharing my C# code for Netduino 2 here. The project uses Ultrasonic distance sensor (HC-SR04) with 8x8 LED matrix (available in Adafruit store http://www.adafruit.com/products/872 ). When the object is close the whole LED matrix is ON, when the object moves far away the number of LEDs which are ON reduces. It also generates sound based on the proximity of the object.

 
Pin 5: SONAR trigger,
Pin 0: SONAR Echo
Pin 6: Speaker
SCL: LED Matrix clock 
SDL: LED Matrix data
make VCC and Gnd connections to +5V and GND
 

 

Run this program in the file attached.
 

I will be writing cleaner library with classes etc later. Any suggestion to improve the efficiency of the code is welcome.

Attached Files



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 04 August 2013 - 11:20 PM

well, you should use a multi i2c class, its makes it look way nicer.

 

also:

byte[] data = new byte[bufferSize];
  data[0] = 0x00; // Going to starting address

  for (uint i = 1; i < bufferSize; i += 2)
  {
  data[i] = 0x00;
  data[i + 1] = 0x00;
  }

 

isent needed

 

byte[] data = new byte[bufferSize];

sets every item in the array to 0x00 allready

 

than:

PWM trig = new PWM(Cpu.PWMChannel.PWM_0,60000,10, PWM.ScaleFactor.Microseconds, false);

dont use Cpu.whatever.

its PWMChannels.yourpin

 

another suggestion: dont use static all the time.

http://pastebin.com/9BBHnWA3 > anti static :P



#3 Shivaram K R

Shivaram K R

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationIndia

Posted 05 August 2013 - 03:42 AM

Thank you :) , Yes I need to use a class instead of using everything in Main...

 

well, you should use a multi i2c class, its makes it look way nicer.

 

also:

byte[] data = new byte[bufferSize];
  data[0] = 0x00; // Going to starting address

  for (uint i = 1; i < bufferSize; i += 2)
  {
  data[i] = 0x00;
  data[i + 1] = 0x00;
  }

 

isent needed

 

byte[] data = new byte[bufferSize];

sets every item in the array to 0x00 allready

 

than:

PWM trig = new PWM(Cpu.PWMChannel.PWM_0,60000,10, PWM.ScaleFactor.Microseconds, false);

dont use Cpu.whatever.

its PWMChannels.yourpin

 

another suggestion: dont use static all the time.

http://pastebin.com/9BBHnWA3 > anti static :P



#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 05 August 2013 - 06:11 AM

I am sharing my C# code for Netduino 2 here.

 

 

 

Welcome to the Forums!

Sharing is what makes this a great place to be.

Paul







Also tagged with one or more of these keywords: Netduino 2, ultrasonic sensor, I2C, PWM

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.