极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22880|回复: 8

Arduino & Processing 超音波雷达问题

[复制链接]
发表于 2013-10-26 18:41:09 | 显示全部楼层 |阅读模式
本帖最后由 sunbluegogo 于 2013-10-26 18:44 编辑

有天看到這篇
Arduino + Processing – Make a Radar Screen to Visualise Sensor Data from SRF-05

http://luckylarry.co.uk/arduino-projects/arduino-processing-make-a-radar-screen-to-visualise-sensor-data-from-srf-05-part-2-visualising-the-data/



剛好手邊有現成材料想試試看
虽然步骤看起来很简单,
但是Processing的图就是不会动作
检查过程式码也只在Arduino那里发现少了「<Servo.h> 」而已
想问问看板上有没有朋友知道是哪里有问题?

我的软体环境
Arduino 0023
Processing 2.0.3

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-10-27 11:00:51 | 显示全部楼层
哇哦,看上去很 cool,   能做到电影里长出现的那种效果,图示方式检测到运动周边运动物体?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-29 10:39:06 | 显示全部楼层
理论上可以检测到运动的物体
这个真的很cool
回复 支持 反对

使用道具 举报

发表于 2014-12-9 22:39:43 | 显示全部楼层
你的Processing 沒有連到序列阜
回复 支持 反对

使用道具 举报

发表于 2014-12-26 22:33:25 | 显示全部楼层

已经重新修复好了,代码如下:

IDE代码:
  1. /*
  2. luckylarry.co.uk
  3. Radar Screen Visualisation for SRF-05
  4. Sends sensor readings for every degree moved by the servo
  5. values sent to serial port to be picked up by Processing
  6. */
  7. #include <Servo.h>           // include the standard servo library
  8. Servo leftRightServo;         // set a variable to map the servo
  9. int leftRightPos = 0;         // set a variable to store the servo position
  10. const int numReadings = 10;   // set a variable for the number of readings to take
  11. int index = 0;                // the index of the current reading
  12. int total = 0;                // the total of all readings
  13. int average = 0;              // the average
  14. int echoPin = 2;              // the SRF05's echo pin
  15. int initPin = 3;              // the SRF05's init pin
  16. unsigned long pulseTime = 0;  // variable for reading the pulse
  17. unsigned long distance = 0;   // variable for storing distance

  18. /* setup the pins, servo and serial port */
  19. void setup() {
  20.   leftRightServo.attach(9);
  21.   // make the init pin an output:
  22.   pinMode(initPin, OUTPUT);
  23.   // make the echo pin an input:
  24.   pinMode(echoPin, INPUT);
  25.   // initialize the serial port:
  26.   Serial.begin(9600);
  27. }

  28. /* begin rotating the servo and getting sensor values */
  29. void loop() {
  30.   for (leftRightPos = 0; leftRightPos < 180; leftRightPos++) { // going left to right.
  31.     leftRightServo.write(leftRightPos);
  32.     for (index = 0; index <= numReadings; index++) {         // take x number of readings from the sensor and average them
  33.       digitalWrite(initPin, LOW);
  34.       delayMicroseconds(50);
  35.       digitalWrite(initPin, HIGH);                           // send signal
  36.       delayMicroseconds(50);                                 // wait 50 microseconds for it to return
  37.       digitalWrite(initPin, LOW);                            // close signal
  38.       pulseTime = pulseIn(echoPin, HIGH);                    // calculate time for signal to return
  39.       distance = pulseTime / 58;                             // convert to centimetres
  40.       total = total + distance;                              // update total
  41.       delay(10);
  42.     }
  43.     average = total / numReadings;                             // create average reading

  44.     if (index >= numReadings)  {                               // reset the counts when at the last item of the array
  45.       index = 0;
  46.       total = 0;
  47.     }
  48.     Serial.print("X");                                         // print leading X to mark the following value as degrees
  49.     Serial.print(leftRightPos);                                // current servo position
  50.     Serial.print("V");                                         // preceeding character to separate values
  51.     Serial.println(average);                                   // average of sensor readings
  52.   }
  53.   /*
  54.   start going right to left after we got to 180 degrees
  55.   same code as above
  56.   */
  57.   for (leftRightPos = 180; leftRightPos > 0; leftRightPos--) { // going right to left
  58.     leftRightServo.write(leftRightPos);
  59.     for (index = 0; index <= numReadings; index++) {
  60.       digitalWrite(initPin, LOW);
  61.       delayMicroseconds(50);
  62.       digitalWrite(initPin, HIGH);
  63.       delayMicroseconds(50);
  64.       digitalWrite(initPin, LOW);
  65.       pulseTime = pulseIn(echoPin, HIGH);
  66.       distance = pulseTime / 58;
  67.       total = total + distance;
  68.       delay(10);
  69.     }
  70.     average = total / numReadings;
  71.     if (index >= numReadings)  {
  72.       index = 0;
  73.       total = 0;
  74.     }
  75.     Serial.print("X");
  76.     Serial.print(leftRightPos);
  77.     Serial.print("V");
  78.     Serial.println(average);
  79.   }
  80. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2014-12-26 22:43:22 | 显示全部楼层


修改成功 代码如下:

  1. /*
  2. luckylarry.co.uk
  3. Radar Screen Visualisation for SRF-05
  4. Sends sensor readings for every degree moved by the servo
  5. values sent to serial port to be picked up by Processing
  6. */
  7. #include <Servo.h>           // include the standard servo library
  8. Servo leftRightServo;         // set a variable to map the servo
  9. int leftRightPos = 0;         // set a variable to store the servo position
  10. const int numReadings = 10;   // set a variable for the number of readings to take
  11. int index = 0;                // the index of the current reading
  12. int total = 0;                // the total of all readings
  13. int average = 0;              // the average
  14. int echoPin = 2;              // the SRF05's echo pin
  15. int initPin = 3;              // the SRF05's init pin
  16. unsigned long pulseTime = 0;  // variable for reading the pulse
  17. unsigned long distance = 0;   // variable for storing distance

  18. /* setup the pins, servo and serial port */
  19. void setup() {
  20.   leftRightServo.attach(9);
  21.   // make the init pin an output:
  22.   pinMode(initPin, OUTPUT);
  23.   // make the echo pin an input:
  24.   pinMode(echoPin, INPUT);
  25.   // initialize the serial port:
  26.   Serial.begin(9600);
  27. }

  28. /* begin rotating the servo and getting sensor values */
  29. void loop() {
  30.   for (leftRightPos = 0; leftRightPos < 180; leftRightPos++) { // going left to right.
  31.     leftRightServo.write(leftRightPos);
  32.     for (index = 0; index <= numReadings; index++) {         // take x number of readings from the sensor and average them
  33.       digitalWrite(initPin, LOW);
  34.       delayMicroseconds(50);
  35.       digitalWrite(initPin, HIGH);                           // send signal
  36.       delayMicroseconds(50);                                 // wait 50 microseconds for it to return
  37.       digitalWrite(initPin, LOW);                            // close signal
  38.       pulseTime = pulseIn(echoPin, HIGH);                    // calculate time for signal to return
  39.       distance = pulseTime / 58;                             // convert to centimetres
  40.       total = total + distance;                              // update total
  41.       delay(10);
  42.     }
  43.     average = total / numReadings;                             // create average reading

  44.     if (index >= numReadings)  {                               // reset the counts when at the last item of the array
  45.       index = 0;
  46.       total = 0;
  47.     }
  48.     Serial.print("X");                                         // print leading X to mark the following value as degrees
  49.     Serial.print(leftRightPos);                                // current servo position
  50.     Serial.print("V");                                         // preceeding character to separate values
  51.     Serial.println(average);                                   // average of sensor readings
  52.   }
  53.   /*
  54.   start going right to left after we got to 180 degrees
  55.   same code as above
  56.   */
  57.   for (leftRightPos = 180; leftRightPos > 0; leftRightPos--) { // going right to left
  58.     leftRightServo.write(leftRightPos);
  59.     for (index = 0; index <= numReadings; index++) {
  60.       digitalWrite(initPin, LOW);
  61.       delayMicroseconds(50);
  62.       digitalWrite(initPin, HIGH);
  63.       delayMicroseconds(50);
  64.       digitalWrite(initPin, LOW);
  65.       pulseTime = pulseIn(echoPin, HIGH);
  66.       distance = pulseTime / 58;
  67.       total = total + distance;
  68.       delay(10);
  69.     }
  70.     average = total / numReadings;
  71.     if (index >= numReadings)  {
  72.       index = 0;
  73.       total = 0;
  74.     }
  75.     Serial.print("X");
  76.     Serial.print(leftRightPos);
  77.     Serial.print("V");
  78.     Serial.println(average);
  79.   }
  80. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2014-12-26 22:46:14 | 显示全部楼层
为什么我已回复就删掉的?
回复 支持 反对

使用道具 举报

发表于 2014-12-26 22:47:00 | 显示全部楼层
修改成功:

  1. /*
  2. luckylarry.co.uk
  3. Radar Screen Visualisation for SRF-05
  4. Sends sensor readings for every degree moved by the servo
  5. values sent to serial port to be picked up by Processing
  6. */
  7. #include <Servo.h>           // include the standard servo library
  8. Servo leftRightServo;         // set a variable to map the servo
  9. int leftRightPos = 0;         // set a variable to store the servo position
  10. const int numReadings = 10;   // set a variable for the number of readings to take
  11. int index = 0;                // the index of the current reading
  12. int total = 0;                // the total of all readings
  13. int average = 0;              // the average
  14. int echoPin = 2;              // the SRF05's echo pin
  15. int initPin = 3;              // the SRF05's init pin
  16. unsigned long pulseTime = 0;  // variable for reading the pulse
  17. unsigned long distance = 0;   // variable for storing distance

  18. /* setup the pins, servo and serial port */
  19. void setup() {
  20.   leftRightServo.attach(9);
  21.   // make the init pin an output:
  22.   pinMode(initPin, OUTPUT);
  23.   // make the echo pin an input:
  24.   pinMode(echoPin, INPUT);
  25.   // initialize the serial port:
  26.   Serial.begin(9600);
  27. }

  28. /* begin rotating the servo and getting sensor values */
  29. void loop() {
  30.   for (leftRightPos = 0; leftRightPos < 180; leftRightPos++) { // going left to right.
  31.     leftRightServo.write(leftRightPos);
  32.     for (index = 0; index <= numReadings; index++) {         // take x number of readings from the sensor and average them
  33.       digitalWrite(initPin, LOW);
  34.       delayMicroseconds(50);
  35.       digitalWrite(initPin, HIGH);                           // send signal
  36.       delayMicroseconds(50);                                 // wait 50 microseconds for it to return
  37.       digitalWrite(initPin, LOW);                            // close signal
  38.       pulseTime = pulseIn(echoPin, HIGH);                    // calculate time for signal to return
  39.       distance = pulseTime / 58;                             // convert to centimetres
  40.       total = total + distance;                              // update total
  41.       delay(10);
  42.     }
  43.     average = total / numReadings;                             // create average reading

  44.     if (index >= numReadings)  {                               // reset the counts when at the last item of the array
  45.       index = 0;
  46.       total = 0;
  47.     }
  48.     Serial.print("X");                                         // print leading X to mark the following value as degrees
  49.     Serial.print(leftRightPos);                                // current servo position
  50.     Serial.print("V");                                         // preceeding character to separate values
  51.     Serial.println(average);                                   // average of sensor readings
  52.   }
  53.   /*
  54.   start going right to left after we got to 180 degrees
  55.   same code as above
  56.   */
  57.   for (leftRightPos = 180; leftRightPos > 0; leftRightPos--) { // going right to left
  58.     leftRightServo.write(leftRightPos);
  59.     for (index = 0; index <= numReadings; index++) {
  60.       digitalWrite(initPin, LOW);
  61.       delayMicroseconds(50);
  62.       digitalWrite(initPin, HIGH);
  63.       delayMicroseconds(50);
  64.       digitalWrite(initPin, LOW);
  65.       pulseTime = pulseIn(echoPin, HIGH);
  66.       distance = pulseTime / 58;
  67.       total = total + distance;
  68.       delay(10);
  69.     }
  70.     average = total / numReadings;
  71.     if (index >= numReadings)  {
  72.       index = 0;
  73.       total = 0;
  74.     }
  75.     Serial.print("X");
  76.     Serial.print(leftRightPos);
  77.     Serial.print("V");
  78.     Serial.println(average);
  79.   }
  80. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2015-11-17 13:26:20 | 显示全部楼层
我在研究这个,原来有人已经成功了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 02:14 , Processed in 0.042019 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表