Raspberry with Maxbotics

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

Moderator: phalanx

Raspberry with Maxbotics

Postby Geeva » Fri Jun 16, 2017 1:06 am

1: Now, I am using Raspberry Pi with Ultrasonic HCSR 04 Sensor. I have written a program for that. I got a proper result, but I am facing some reliability issue with that. So I thought I will use other sensors.

Statement 2: I bought Maxbotics sensor MB 1040, but I don't know how to program. I have tried with the same ultrasonic program, I got readings but that is not proper reading, I have not achieved accuracy. I have written a program in C++. So kindly help me to solve this issue.

Here I have added my sample code, what I have tried. I hope here will get a solution.

Code: Select all
#define TRIGGER_SENSOR 7      // GPIO_7
#define ECHO_SENSOR 15          // GPIO_8

// Distance variable
uint32_t Start_Sensor=0,Stop_Sensor=0;
uint32_t Time_Diff_Sensor=0;
float Range_Sensor=0;
volatile int Flag_Sensor=0;

    pinMode(TRIGGER_SENSOR,OUTPUT);             // Pins assignment
    pinMode(ECHO_SENSOR,INPUT);
    pullUpDnControl(ECHO_SENSOR,PUD_DOWN);

float Sensor::SensorDistance() // Sonar function
{
            Start_Sensor=0;
            Stop_Sensor= 0;
            Flag_Sensor= 0;
            digitalWrite(TRIGGER_SENSOR,0);
            delayMicroseconds(1);
            digitalWrite(TRIGGER_SENSOR,1);
            delayMicroseconds(10);
            digitalWrite(TRIGGER_SENSOR,0);
            return Range_Sensor;
}

void myInterruptSensor(void) // Interrupt routine for Sensor distance
 {                     // Called whenever the input pin toggles
    uint32_t timeTempSensorultra=micros();
    if(Flag_Sensor==0) // first toggle? note the time
      {
            Start_Sensor=timeTempSensorultra;
            Flag_Sensor=1;
      }
    else // second toggle? compute the distance
      {
            Stop_Sensor=timeTempSensorultra;
            Flag_Sensor=0;
            Time_Diff_Sensor=Stop_Sensor-Start_Sensor;
            Range_Sensor=Time_Diff_Sensor/58.;
       }
  }

bool Sensor::Interrupt_error()
{
    if(wiringPiISR(ECHO_SENSOR,INT_EDGE_BOTH,&myInterruptSensor) < 0)
        {
            cerr<<"interrupt error ["<<strerror (errno)<< "]:"<<errno<<endl;
            return false;
        }
        return true;
}
Geeva
 
Posts: 1
Joined: Fri Jun 16, 2017 12:39 am


Return to Projects

Who is online

Users browsing this forum: No registered users and 3 guests