473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use Distance Sensor with Unity3D and Raspberry Pi

1
Hi

So I set up Mono for my Raspberry Pi that I can use C#.
I'm converting a analog signal to a digital signal with a MCP3008. Now I want to use this signal in Unity3D to scale an Object.

This is my script actually:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using RaspberryPiDotNet;
  6.  
  7. namespace RPi_Projekt4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //# set up the SPI interface pins
  14.             //# SPI port on the ADC to the Cobbler
  15.             GPIOMem SPICLK = new GPIOMem(GPIOPins.Pin_P1_18, GPIODirection.Out);
  16.             GPIOMem SPIMISO = new GPIOMem(GPIOPins.Pin_P1_23, GPIODirection.In);
  17.             GPIOMem SPIMOSI = new GPIOMem(GPIOPins.Pin_P1_24, GPIODirection.Out);
  18.             GPIOMem SPICS = new GPIOMem(GPIOPins.Pin_P1_25, GPIODirection.Out);
  19.  
  20.              int adcnum = 0;
  21.             double read_adc0 = 0.0;
  22.  
  23.             while (true)
  24.             {
  25.                 MCP3008 MCP3008 = new MCP3008(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS);
  26.                 // read the analog pin 
  27.                 read_adc0 = MCP3008.AnalogToDigital;
  28.                 double millivolts = Convert.ToDouble(read_adc0) * (3300.0 / 1024);
  29.  
  30.                 double volts = (Convert.ToDouble(read_adc0) / 1024.0f) * 3.3f;
  31.  
  32.  
  33.  
  34. #if DEBUG
  35.                 System.Console.WriteLine("MCP3008_Channel: " + adcnum);
  36.                 System.Console.WriteLine("read_adc0: " + read_adc0);
  37.                 System.Console.WriteLine("millivolts: " + (float)millivolts);
  38.                 System.Console.WriteLine("distance: " + (float)distance);
  39.                 System.Console.WriteLine("volts: " + (float)volts);
  40.  
  41. #endif
  42.                 Thread.Sleep(3000);
  43.             }
  44.         }
  45.     }
  46. }
  47.  
So I'm stuck after the conversion of the signal and the conversion in volts. I want to use the volts to scale the object in Unity 3D but I don't know how.

Can someone help please.
Jan 8 '16 #1
0 1744

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
10
by: Alan Johnson | last post by:
24.1.1.3 says about InputIterators: Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms. In 24.3.4.4 summarizes the...
9
by: nottheartistinquestion | last post by:
As an intellectual exercise, I've implemented an STL-esque List<and List<>::Iterator. Now, I would like a signed distance between two iterators which corresponds to their relative position in the...
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
1
by: tiffrobe | last post by:
I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. ...
11
by: devnew | last post by:
hello while trying to write a function that processes some numpy arrays and calculate euclidean distance ,i ended up with this code (though i used numpy ,i believe my problem has more to do with...
2
by: 0654wil | last post by:
Hi, I am trying to display my sensor's output (HEX to ASCII output type) onto the hyperterminal program through UART coding. To display the fluctuations of the sensor when something is...
1
by: 7suji | last post by:
wanna know... is neo4j will support for unity3d as a back-end database??
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.