Click here to Skip to main content
15,074,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
unsigned int counter=0;

int b1a = 6;  // L9110 B-1A 
int b1b = 9;  // L9110 B-1B

void docount()  // counts from the speed sensor
  counter++;  // increase +1 the counter value

void timerIsr()
  Timer1.detachInterrupt();  //stop the timer
  Serial.print("Motor Speed: "); 
  int rotation = (counter / 20);  // divide by number of holes in Disc
  Serial.println(" Rotation per seconds"); 
  counter=0;  //  reset counter to zero
  Timer1.attachInterrupt( timerIsr );  //enable the timer

void setup() 
 pinMode(b1a, OUTPUT); 
 pinMode(b1b, OUTPUT); 
  Timer1.initialize(1000000); // set timer for 1sec
  attachInterrupt(0, docount, RISING);  // increase counter when speed sensor pin goes High
  Timer1.attachInterrupt( timerIsr ); // enable the timer

void loop()
  int potvalue = analogRead(1);  // Potentiometer connected to Pin A1
  int motorspeed = map(potvalue, 0, 680, 255, 0);
  analogWrite(b1a, motorspeed);  // set speed of motor (0-255)
  digitalWrite(b1b, 1);  // set rotation of motor to Clockwise

What I have tried:

from RPi import GPIO
from time import sleep

d0 = 7

GPIO.setup(d0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

counter = 0
d0LastState = False

        while True:
                currentState = GPIO.input(d0)
                print (counter)
                if currentState != d0LastState:
                        counter +=1
                d0LastState = currentState

Updated 27-Nov-17 3:57am
Richard MacCutchan 27-Nov-17 3:59am
Sorry but this site does not provide free code writing or converting services.

1 solution

Neither the LM393 (dual comparator analog IC) nor the L9110 (dual channel motor driver) is a speed sensor.

We can't even help when guessing that the code in the Arduino loop() function is reading the value from a speed sensor:
That function reads an analog input which the Raspberry Pi does not have. It has only digital ports.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900