468,740 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

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 1384

Post your reply

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

Similar topics

20 posts views Thread by Xenophobe | last post: by
10 posts views Thread by Alan Johnson | last post: by
9 posts views Thread by nottheartistinquestion | last post: by
18 posts views Thread by lovecreatesbea... | last post: by
11 posts views Thread by devnew | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.