How can I get raspberry pi 4b to read a TSL237 LF sensor?

  arduino, python-3.x, raspberry-pi

I have the sensor working on an Arduino UNO. I’m having trouble translating the code over.
I can get the pi to receive input from the sensor, but I’m not sure how to get it to read the rising pulses for a specific amount of time (10 seconds) to give a certain number of pulses.

In this code the arduino is still receiving pulses from the sensor during the 10 second delay, but the number will vary based on how much light is getting through, which is what I want. I want the pi to do the same thing.

Also please understand I’m very much a novice, so if you can explain in detail I’d appreciate it.

#define TSL237  2
volatile unsigned long pulse_cnt = 0;


void setup() {
 attachInterrupt(0, add_pulse, RISING);
 pinMode(TSL237, INPUT);
 Serial.begin(9600);
}

void add_pulse(){
  pulse_cnt++;
  return;
}

unsigned long Frequency() { 
    
 pulse_cnt = 0;
 delay(10000);// this delay controlls pulse_cnt read out. longer delay == higher number
   // DO NOT change this delay; it will void calibration.
 unsigned long frequency = pulse_cnt;
 return (frequency);
 pulse_cnt = 0;    
 }
void loop() {
   unsigned long frequency = Frequency();
   Serial.println(frequency);
   delay(5000);
      
}

here is what I have tried in MU, but I’m not as skilled.

import threading
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

TSL237 = 16

GPIO.setup(TSL237, GPIO.IN, pull_up_down=GPIO.PUD_OFF)


class TSL237():
    def __init__(self,TSL237):
        self.TSL237 = TSL237



    def Frequency(self):
        self.pulse = 0
        i=0
        while i < 10:
            i += 1
            if GPIO.input(TSL237):
               pulse += 1

        return self.pulse

Reading = TSL237(TSL237)
GPIO.add_event_detect(TSL237, GPIO.RISING, Reading.Frequency())


#threading.Thread(target=TSL237(Frequency)).start()

Source: Python-3x Questions

LEAVE A COMMENT