Skocz do zawartości

APDS9960- sensor gestów,kolorówi światła C-BASCOM-ARDUINO


zuba1

Pomocna odpowiedź

Witam. Na wstępnie klasyk do Pana moderatora-jak złe miejsce to proszę przenieś. Mam niecodzienny problem. Ostatnio wraz z zabawą w arduino nabyłem czujnik gestów APDS9960 na płytce spartak funa. Z racji że wiele moich projektów opiera się o język Bascom. Aplikacja mojego czujnika wymusza na mnie zastosowanie bascoma a instalowanie procesora mostka między czujnikiem a główna aplikacją odpada. Jako że w arduino jestem że tak powiem zielony postanowiłem przepisać wszystko na bascoma. Ambitnie pochwyciłem biblioteki i przepisałem całą instrukcję init-Najpewniej błędnie. Z datasheta wiem co nieco lecz na jego podstawie nie potrafię sklepać niczego pewnego. Po prostu mam mętlik z tymi rejestrami.Nie wiem co mam czytać. Żeby nie było dodaję wszelkie materiały które udało mi się zgromadzić.

Na początek co chcę osiągnąć:

-chcę rozpoznawać podstawowe gesty

-sprawdzać obecną gamę barw RGB

-sprawdzać jasność choć to można osiągnąć na dwa sposoby czyli albo przez RGB lub skorzystać z czwartego sensora w układzie czyli W- rozpoznający całą składnię barwy białej

Obecne materiały:

Dysponuję Kodem z arduino:

+/**
+ * @file    SparkFun_APDS-9960.h
+ * @brief   Library for the SparkFun APDS-9960 breakout board
+ * @author  Shawn Hymel (SparkFun Electronics)
+ *
+ * @copyright This code is public domain but you buy me a beer if you use
+ * this and we meet someday (Beerware license).
+ *
+ * This library interfaces the Avago APDS-9960 to Arduino over I2C. The library
+ * relies on the Arduino Wire (I2C) library. to use the library, instantiate an
+ * APDS9960 object, call init(), and call the appropriate functions.
+ */
+
+#ifndef SparkFun_APDS9960_H
+#define SparkFun_APDS9960_H
+
+#include <Arduino.h>
+
+/* Debug */
+#define DEBUG                   0
+
+/* APDS-9960 I2C address */
+#define APDS9960_I2C_ADDR       0x39
+
+/* Gesture parameters */
+#define GESTURE_THRESHOLD_OUT   10
+#define GESTURE_SENSITIVITY_1   50
+#define GESTURE_SENSITIVITY_2   20
+
+/* Error code for returned values */
+#define ERROR                   0xFF
+
+/* Acceptable device IDs */
+#define APDS9960_ID_1           0xAB
+#define APDS9960_ID_2           0x9C
+
+/* Misc parameters */
+#define FIFO_PAUSE_TIME         30      // Wait period (ms) between FIFO reads
+
+/* APDS-9960 register addresses */
+#define APDS9960_ENABLE         0x80
+#define APDS9960_ATIME          0x81
+#define APDS9960_WTIME          0x83
+#define APDS9960_AILTL          0x84
+#define APDS9960_AILTH          0x85
+#define APDS9960_AIHTL          0x86
+#define APDS9960_AIHTH          0x87
+#define APDS9960_PILT           0x89
+#define APDS9960_PIHT           0x8B
+#define APDS9960_PERS           0x8C
+#define APDS9960_CONFIG1        0x8D
+#define APDS9960_PPULSE         0x8E
+#define APDS9960_CONTROL        0x8F
+#define APDS9960_CONFIG2        0x90
+#define APDS9960_ID             0x92
+#define APDS9960_STATUS         0x93
+#define APDS9960_CDATAL         0x94
+#define APDS9960_CDATAH         0x95
+#define APDS9960_RDATAL         0x96
+#define APDS9960_RDATAH         0x97
+#define APDS9960_GDATAL         0x98
+#define APDS9960_GDATAH         0x99
+#define APDS9960_BDATAL         0x9A
+#define APDS9960_BDATAH         0x9B
+#define APDS9960_PDATA          0x9C
+#define APDS9960_POFFSET_UR     0x9D
+#define APDS9960_POFFSET_DL     0x9E
+#define APDS9960_CONFIG3        0x9F
+#define APDS9960_GPENTH         0xA0
+#define APDS9960_GEXTH          0xA1
+#define APDS9960_GCONF1         0xA2
+#define APDS9960_GCONF2         0xA3
+#define APDS9960_GOFFSET_U      0xA4
+#define APDS9960_GOFFSET_D      0xA5
+#define APDS9960_GOFFSET_L      0xA7
+#define APDS9960_GOFFSET_R      0xA9
+#define APDS9960_GPULSE         0xA6
+#define APDS9960_GCONF3         0xAA
+#define APDS9960_GCONF4         0xAB
+#define APDS9960_GFLVL          0xAE
+#define APDS9960_GSTATUS        0xAF
+#define APDS9960_IFORCE         0xE4
+#define APDS9960_PICLEAR        0xE5
+#define APDS9960_CICLEAR        0xE6
+#define APDS9960_AICLEAR        0xE7
+#define APDS9960_GFIFO_U        0xFC
+#define APDS9960_GFIFO_D        0xFD
+#define APDS9960_GFIFO_L        0xFE
+#define APDS9960_GFIFO_R        0xFF
+
+/* Bit fields */
+#define APDS9960_PON            0b00000001
+#define APDS9960_AEN            0b00000010
+#define APDS9960_PEN            0b00000100
+#define APDS9960_WEN            0b00001000
+#define APSD9960_AIEN           0b00010000
+#define APDS9960_PIEN           0b00100000
+#define APDS9960_GEN            0b01000000
+#define APDS9960_GVALID         0b00000001
+
+/* On/Off definitions */
+#define OFF                     0
+#define ON                      1
+
+/* Acceptable parameters for setMode */
+#define POWER                   0
+#define AMBIENT_LIGHT           1
+#define PROXIMITY               2
+#define WAIT                    3
+#define AMBIENT_LIGHT_INT       4
+#define PROXIMITY_INT           5
+#define GESTURE                 6
+#define ALL                     7
+
+/* LED Drive values */
+#define LED_DRIVE_100MA         0
+#define LED_DRIVE_50MA          1
+#define LED_DRIVE_25MA          2
+#define LED_DRIVE_12_5MA        3
+
+/* Proximity Gain (PGAIN) values */
+#define PGAIN_1X                0
+#define PGAIN_2X                1
+#define PGAIN_4X                2
+#define PGAIN_8X                3
+
+/* ALS Gain (AGAIN) values */
+#define AGAIN_1X                0
+#define AGAIN_4X                1
+#define AGAIN_16X               2
+#define AGAIN_64X               3
+
+/* Gesture Gain (GGAIN) values */
+#define GGAIN_1X                0
+#define GGAIN_2X                1
+#define GGAIN_4X                2
+#define GGAIN_8X                3
+
+/* LED Boost values */
+#define LED_BOOST_100           0
+#define LED_BOOST_150           1
+#define LED_BOOST_200           2
+#define LED_BOOST_300           3
+
+/* Gesture wait time values */
+#define GWTIME_0MS              0
+#define GWTIME_2_8MS            1
+#define GWTIME_5_6MS            2
+#define GWTIME_8_4MS            3
+#define GWTIME_14_0MS           4
+#define GWTIME_22_4MS           5
+#define GWTIME_30_8MS           6
+#define GWTIME_39_2MS           7
+
+/* Default values */
+#define DEFAULT_ATIME           219     // 103ms
+#define DEFAULT_WTIME           246     // 27ms
+#define DEFAULT_PROX_PPULSE     0x87    // 16us, 8 pulses
+#define DEFAULT_GESTURE_PPULSE  0x89    // 16us, 10 pulses
+#define DEFAULT_POFFSET_UR      0       // 0 offset
+#define DEFAULT_POFFSET_DL      0       // 0 offset
+#define DEFAULT_CONFIG1         0x60    // No 12x wait (WTIME) factor
+#define DEFAULT_LDRIVE          LED_DRIVE_100MA
+#define DEFAULT_PGAIN           PGAIN_4X
+#define DEFAULT_AGAIN           AGAIN_4X
+#define DEFAULT_PILT            0       // Low proximity threshold
+#define DEFAULT_PIHT            50      // High proximity threshold
+#define DEFAULT_AILT            0xFFFF  // Force interrupt for calibration
+#define DEFAULT_AIHT            0
+#define DEFAULT_PERS            0x11    // 2 consecutive prox or ALS for int.
+#define DEFAULT_CONFIG2         0x01    // No saturation interrupts or LED boost
+#define DEFAULT_CONFIG3         0       // Enable all photodiodes, no SAI
+#define DEFAULT_GPENTH          40      // Threshold for entering gesture mode
+#define DEFAULT_GEXTH           30      // Threshold for exiting gesture mode
+#define DEFAULT_GCONF1          0x40    // 4 gesture events for int., 1 for exit
+#define DEFAULT_GGAIN           GGAIN_4X
+#define DEFAULT_GLDRIVE         LED_DRIVE_100MA
+#define DEFAULT_GWTIME          GWTIME_2_8MS
+#define DEFAULT_GOFFSET         0       // No offset scaling for gesture mode
+#define DEFAULT_GPULSE          0xC9    // 32us, 10 pulses
+#define DEFAULT_GCONF3          0       // All photodiodes active during gesture
+#define DEFAULT_GIEN            0       // Disable gesture interrupts
+
+/* Direction definitions */
+enum {
+  DIR_NONE,
+  DIR_LEFT,
+  DIR_RIGHT,
+  DIR_UP,
+  DIR_DOWN,
+  DIR_NEAR,
+  DIR_FAR,
+  DIR_ALL
+};
+
+/* State definitions */
+enum {
+  NA_STATE,
+  NEAR_STATE,
+  FAR_STATE,
+  ALL_STATE
+};
+
+/* Container for gesture data */
+typedef struct gesture_data_type {
+    uint8_t u_data[32];
+    uint8_t d_data[32];
+    uint8_t l_data[32];
+    uint8_t r_data[32];
+    uint8_t index;
+    uint8_t total_gestures;
+    uint8_t in_threshold;
+    uint8_t out_threshold;
+} gesture_data_type;
+
+/* APDS9960 Class */
+class SparkFun_APDS9960 {
+public:
+
+    /* Initialization methods */
+    SparkFun_APDS9960();
+    ~SparkFun_APDS9960();
+    bool init();
+    uint8_t getMode();
+    bool setMode(uint8_t mode, uint8_t enable);
+
+    /* Turn the APDS-9960 on and off */
+    bool enablePower();
+    bool disablePower();
+
+    /* Enable or disable specific sensors */
+    bool enableLightSensor(bool interrupts = false);
+    bool disableLightSensor();
+    bool enableProximitySensor(bool interrupts = false);
+    bool disableProximitySensor();
+    bool enableGestureSensor(bool interrupts = true);
+    bool disableGestureSensor();
+
+    /* LED drive strength control */
+    uint8_t getLEDDrive();
+    bool setLEDDrive(uint8_t drive);
+    uint8_t getGestureLEDDrive();
+    bool setGestureLEDDrive(uint8_t drive);
+
+    /* Gain control */
+    uint8_t getAmbientLightGain();
+    bool setAmbientLightGain(uint8_t gain);
+    uint8_t getProximityGain();
+    bool setProximityGain(uint8_t gain);
+    uint8_t getGestureGain();
+    bool setGestureGain(uint8_t gain);
+
+    /* Get and set light interrupt thresholds */
+    bool getLightIntLowThreshold(uint16_t &threshold);
+    bool setLightIntLowThreshold(uint16_t threshold);
+    bool getLightIntHighThreshold(uint16_t &threshold);
+    bool setLightIntHighThreshold(uint16_t threshold);
+
+    /* Get and set proximity interrupt thresholds */
+    bool getProximityIntLowThreshold(uint8_t &threshold);
+    bool setProximityIntLowThreshold(uint8_t threshold);
+    bool getProximityIntHighThreshold(uint8_t &threshold);
+    bool setProximityIntHighThreshold(uint8_t threshold);
+
+    /* Get and set interrupt enables */
+    uint8_t getAmbientLightIntEnable();
+    bool setAmbientLightIntEnable(uint8_t enable);
+    uint8_t getProximityIntEnable();
+    bool setProximityIntEnable(uint8_t enable);
+    uint8_t getGestureIntEnable();
+    bool setGestureIntEnable(uint8_t enable);
+
+    /* Clear interrupts */
+    bool clearAmbientLightInt();
+    bool clearProximityInt();
+
+    /* Ambient light methods */
+    bool readAmbientLight(uint16_t &val);
+    bool readRedLight(uint16_t &val);
+    bool readGreenLight(uint16_t &val);
+    bool readBlueLight(uint16_t &val);
+
+    /* Proximity methods */
+    bool readProximity(uint8_t &val);
+
+    /* Gesture methods */
+    bool isGestureAvailable();
+    int readGesture();
+
+private:
+
+    /* Gesture processing */
+    void resetGestureParameters();
+    bool processGestureData();
+    bool decodeGesture();
+
+    /* Proximity Interrupt Threshold */
+    uint8_t getProxIntLowThresh();
+    bool setProxIntLowThresh(uint8_t threshold);
+    uint8_t getProxIntHighThresh();
+    bool setProxIntHighThresh(uint8_t threshold);
+
+    /* LED Boost Control */
+    uint8_t getLEDBoost();
+    bool setLEDBoost(uint8_t boost);
+
+    /* Proximity photodiode select */
+    uint8_t getProxGainCompEnable();
+    bool setProxGainCompEnable(uint8_t enable);
+    uint8_t getProxPhotoMask();
+    bool setProxPhotoMask(uint8_t mask);
+
+    /* Gesture threshold control */
+    uint8_t getGestureEnterThresh();
+    bool setGestureEnterThresh(uint8_t threshold);
+    uint8_t getGestureExitThresh();
+    bool setGestureExitThresh(uint8_t threshold);
+
+    /* Gesture LED, gain, and time control */
+    uint8_t getGestureWaitTime();
+    bool setGestureWaitTime(uint8_t time);
+
+    /* Gesture mode */
+    uint8_t getGestureMode();
+    bool setGestureMode(uint8_t mode);
+
+    /* Raw I2C Commands */
+    bool wireWriteByte(uint8_t val);
+    bool wireWriteDataByte(uint8_t reg, uint8_t val);
+    bool wireWriteDataBlock(uint8_t reg, uint8_t *val, unsigned int len);
+    bool wireReadDataByte(uint8_t reg, uint8_t &val);
+    int wireReadDataBlock(uint8_t reg, uint8_t *val, unsigned int len);
+
+    /* Members */
+    gesture_data_type gesture_data_;
+    int gesture_ud_delta_;
+    int gesture_lr_delta_;
+    int gesture_ud_count_;
+    int gesture_lr_count_;
+    int gesture_near_count_;
+    int gesture_far_count_;
+    int gesture_state_;
+    int gesture_motion_;
+};
+
 + #endif



A teraz moje skromne wypociny w bascomie:

'test board  atmega8
                           $regfile = "m8def.dat"
$crystal = 8000000

Config Pinb.0 = Input
Sw Alias Pinb.0

Config Portb.1 = Output
Led Alias Portb.1

Config Portd = Output

Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 16 * 2
Cursor Off
'Cursor Blink
Enable Interrupts
Cls

'Config Adc = Single , Prescaler = Auto , Reference = Avcc
'Start Adc

'Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up

'Pwm1a = 100
'Pwm1b = 39

'program
'*********************************************************************************************
' + #define Debug 0
Const Apds9960_i2c_addr = &H39
'Gesture parameters
Const Gesture_threshold_out = 10
Const Gesture_sensitivity_1 = 50
Const Gesture_sensitivity_2 = 20
' Error code for returned values
Const Error = &HFF
'Acceptable device IDs
Const Apds9960_id_1 = &HAB
Const Apds9960_id_2 = &H9C
'Misc parameters */
Const Fifo_pause_time = 30                                  'Wait Period(ms) Between Fifo Reads
'APDS-9960 register addresses
Const Apds9960_enable = &H80
Const Apds9960_atime = &H81
Const Apds9960_wtime = &H83
Const Apds9960_ailtl = &H84
Const Apds9960_ailth = &H85
Const Apds9960_aihtl = &H86
Const Apds9960_aihth = &H87
Const Apds9960_pilt = &H89
Const Apds9960_piht = &H8B
Const Apds9960_pers = &H8C
Const Apds9960_config1 = &H8D
Const Apds9960_ppulse = &H8E
Const Apds9960_control = &H8F
Const Apds9960_config2 = &H90
Const Apds9960_id = &H92
Const Apds9960_status = &H93
Const Apds9960_cdatal = &H94
Const Apds9960_cdatah = &H95
Const Apds9960_rdatal = &H96
Const Apds9960_rdatah = &H97
Const Apds9960_gdatal = &H98
Const Apds9960_gdatah = &H99
Const Apds9960_bdatal = &H9A
Const Apds9960_bdatah = &H9B
Const Apds9960_pdata = &H9C
Const Apds9960_poffset_ur = &H9D
Const Apds9960_poffset_dl = &H9E
Const Apds9960_config3 = &H9F
Const Apds9960_gpenth = &HA0
Const Apds9960_gexth = &HA1
Const Apds9960_gconf1 = &HA2
Const Apds9960_gconf2 = &HA3
Const Apds9960_goffset_u = &HA4
Const Apds9960_goffset_d = &HA5
Const Apds9960_goffset_l = &HA7
Const Apds9960_goffset_r = &HA9
Const Apds9960_gpulse = &HA6
Const Apds9960_gconf3 = &HAA
Const Apds9960_gconf4 = &HAB
Const Apds9960_gflvl = &HAE
Const Apds9960_gstatus = &HAF
Const Apds9960_iforce = &HE4
Const Apds9960_piclear = &HE5
Const Apds9960_ciclear = &HE6
Const Apds9960_aiclear = &HE7
Const Apds9960_gfifo_u = &HFC
Const Apds9960_gfifo_d = &HFD
Const Apds9960_gfifo_l = &HFE
Const Apds9960_gfifo_r = &HFF
'Bit fields
Const Apds9960_pon = &B00000001
Const Apds9960_aen = &B00000010
Const Apds9960_pen = &B00000100
Const Apds9960_wen = &B00001000
Const Apsd9960_aien = &B00010000
Const Apds9960_pien = &B00100000
Const Apds9960_gen = &B01000000
Const Apds9960_gvalid = &B00000001
'On/Off definitions */
Const Aoff = 0
Const Aon = 1
'Acceptable parameters for setMode
Const Apower = 0
Const Ambient_light = 1
Const Proximity = 2
Const Await = 3
Const Ambient_light_int = 4
Const Proximity_int = 5
Const Gesture = 6
Const All = 7
'LED Drive values
Const Led_drive_100ma = 0
Const Led_drive_50ma = 1
Const Led_drive_25ma = 2
Const Led_drive_12_5ma = 3
'Proximity Gain (PGAIN) values
Const Pgain_1x = 0
Const Pgain_2x = 1
Const Pgain_4x = 2
Const Pgain_8x = 3
'ALS Gain (AGAIN) values
Const Again_1x = 0
Const Again_4x = 1
Const Again_16x = 2
Const Again_64x = 3
'Gesture Gain (GGAIN) values
Const Ggain_1x = 0
Const Ggain_2x = 1
Const Ggain_4x = 2
Const Ggain_8x = 3
'LED Boost values */
Const Led_boost_100 = 0
Const Led_boost_150 = 1
Const Led_boost_200 = 2
Const Led_boost_300 = 3
'Gesture wait time values
Const Gwtime_0ms = 0
Const Gwtime_2_8ms = 1
Const Gwtime_5_6ms = 2
Const Gwtime_8_4ms = 3
Const Gwtime_14_0ms = 4
Const Gwtime_22_4ms = 5
Const Gwtime_30_8ms = 6
Const Gwtime_39_2ms = 7
'Default values
Const Default_atime = 219                                   '103ms
Const Default_wtime = 246                                   '27ms
Const Default_prox_ppulse = &H87                            '16us , 8 Pulses
Const Default_gesture_ppulse = &H89                         '16us , 10 Pulses
Const Default_poffset_ur = 0                                '0 Offset
Const Default_poffset_dl = 0                                '0 Offset
Const Default_config1 = &H60                                'No 12x Wait(wtime) Factor
Const Default_ldrive = 0
Const Default_pgain = 2
Const Default_again = 1
Const Default_pilt = 0                                      'Low Proximity Threshold
Const Default_piht = 50                                     'High Proximity Threshold
Const Default_ailt = &HFFFF                                 'Force Interrupt For Calibration
Const Default_aiht = 0
Const Default_pers = &H11                                   '2  Consecutive Prox Or Als For Int.
Const Default_config2 = &H01                                ' No Saturation Interrupts Or Led Boost
Const Default_config3 = 0                                   'Enable All Photodiodes , No Sai
Const Default_gpenth = 40                                   'Threshold For Entering Gesture Mode
Const Default_gexth = 30                                    'Threshold For Exiting Gesture Mode
Const Default_gconf1 = &H40                                 '4 Gesture Events For Int. , 1 For Exit
Const Default_ggain = 2
Const Default_gldrive = 0
Const Default_gwtime = 1
Const Default_goffset = 0                                   'No Offset Scaling For Gesture Mode
Const Default_gpulse = &HC9                                 '32us , 10 Pulses
Const Default_gconf3 = 0                                    'All Photodiodes Active During Gesture
Const Default_gien = 0                                      'Disable Gesture Interrupts


$lib "i2c_twi.lbx"
Config Sda = Portc.4
Config Scl = Portc.5
Config Twi = 400000                                         ' Init TWBR und TWSR
Twcr = &B00000100                                           ' nur TWEN setzen

'const
Dim I As Word
Dim A As Word
Dim B As Byte
Dim Dane(10) As Byte
Led = 1
Gosub Apds_init
Do
Gosub Apds_odczyt



Cls
Upperline
Lcd Dane(1) ; " " ; Dane(2)
Lowerline
Lcd Dane(7) ; " " ; Dane(6)
Waitms 500

Loop

Apds_init:
I2cstart
I2cwbyte Apds9960_atime
I2cwbyte Default_atime
I2cstop
Waitms 5

I2cstart
I2cwbyte Apds9960_wtime
I2cwbyte Default_wtime
I2cstop
Waitms 5

I2cstart
I2cwbyte Apds9960_ppulse
I2cwbyte Default_prox_ppulse
I2cstop
Waitms 5

I2cstart
I2cwbyte Apds9960_poffset_ur
I2cwbyte Default_poffset_ur
I2cstop
Waitms 5

I2cstart
I2cwbyte Apds9960_poffset_dl
I2cwbyte DEFAULT_POFFSET_DL
I2cstop
Waitms 5

I2cstart
I2cwbyte APDS9960_CONFIG1
I2cwbyte DEFAULT_CONFIG1
I2cstop
Waitms 5

I2cstart
I2cwbyte APDS9960_PERS
I2cwbyte Default_pers
I2cstop
Waitms 5

I2cstart
I2cwbyte APDS9960_CONFIG2
I2cwbyte Default_config2
I2cstop
Waitms 5

I2cstart
I2cwbyte  APDS9960_CONFIG3
I2cwbyte  Default_config3
I2cstop
Waitms 5

I2cstart
I2cwbyte  APDS9960_GCONF1
I2cwbyte  Default_gconf1
I2cstop
Waitms 5

I2cstart
I2cwbyte  APDS9960_GOFFSET_U
I2cwbyte  Default_goffset
I2cstop
Waitms 5

I2cstart
I2cwbyte  APDS9960_GOFFSET_D
I2cwbyte  Default_goffset
I2cstop
Waitms 5

I2cstart
I2cwbyte   APDS9960_GOFFSET_L
I2cwbyte   Default_goffset
I2cstop
Waitms 5

I2cstart
I2cwbyte   APDS9960_GOFFSET_R
I2cwbyte   Default_goffset
I2cstop
Waitms 5

I2cstart
I2cwbyte   APDS9960_GPULSE
I2cwbyte   Default_gpulse
I2cstop
Waitms 5

I2cstart
I2cwbyte  APDS9960_GCONF3
I2cwbyte  Default_gconf3
I2cstop
Waitms 5





Return


Apds_odczyt:
I2cstart
I2cwbyte &H39
I2cwbyte &H89
I2crbyte Dane(1) , Ack
I2crbyte Dane(2) , Ack
I2crbyte Dane(3) , Ack
I2crbyte Dane(4) , Ack
I2crbyte Dane(5) , Ack
I2crbyte Dane(6) , Nack


I2cstop

Return



Datashet:

https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf

Tak więc panowie widzimy jak to mniej więcej wygląda -a konkretnie nie wygląda. Prosze o wszeklą pomoc. Główne doświatczonych Arduoinowców aby spróbowali rozpisać tą transmisję. Jeśli będę znał rejestry niepowinienem mieć problemów z resztą. Pozdrawiam i z góry dziękuję.

Link do komentarza
Share on other sites

Mam pomysł. Może podłączę go do arduino, wgram originalny program i podepnę pod to drugą atmegę. Następnie będę sprawdzał zbocze clk i w danym zboczu będę zczytywał wartość binarną. Finalnie wyślę je na wyświetlacz LCD. Co myślicie? Czy metoda podsłuchania okaże się skuteczna?

Link do komentarza
Share on other sites

A może to dobry moment, żeby przejść na inny język programowania? Podejrzewam, że robiąc coraz większe projekty coraz częściej będziesz musiał robić takie sztuczki jak tutaj. Oczywiście możesz za każdym razem tracić mnóstwo czasu na ręczne przepisywanie programów i bibliotek, ale sam widzisz, że ma to coraz mniejszy sens.

Nie wiem z jakiego powodu nie chcesz tego zrobić teraz i musisz(?) obsługę czujnika przepisywać na Ś.P. BASCOM. Czy po prostu masz już kawał kodu i zostało "tylko" dołączenie sensora? Czy jednak jest to mały, wewnętrzny strach (nazwijmy to obawą) przed sporą inwestycją? Każdy z nas czasem staje przed takimi ścianami. Ja zawsze mam opór przed zrobieniem czegoś po nowemu i jest to naturalne, ale jeśli się nie pokonasz, staniesz w miejscu. Miałem tak przy przejściu z jednego programu CAD na inny, z TTL na procesor 8080, z 8080 na 8048, z 8048 na 8051, z 8051 na AVR lub PIC, z AVR na ARM itd.. Zawsze jest bariera i musi minąć kilka projektów w których ewidentnie można użyć nowego, tańszego, szybszego i bardziej wygodnego narzędzia/sprzętu, ale Ty (ja) ciągle patrzysz przez pryzymat tego co już znasz. To wydaje się prostsze i oczywiste a nieznane zwykle przeraża. No i ten brak czasu.. A potem sam się dziwię jak mogłem tak długo zwlekać...

Jak już widzisz nie znalazł się nikt, kto zaczął by wgryzać się w Twój kod i analizować czy przepisałeś to poprawnie. Musisz to wziąć na siebie i albo krok po kroku, powoli uruchamiać co mniejsze funkcje głęboko wnikając w działanie samego scalaka i znaczenie jego rejestrów albo od drugiej strony: puszczać wszystko na żywioł a przy pomocy analizatora protokołów sprawdzać, czy na I2C jest to czego się spodziewałeś. Oba podejścia wymagają niestety dobrej orientacji w protokole I2C - w sumie do opanowania i niestety znajomości czujnika. Moim zdaniem nie jest to dobry pomysł na spędzanie wieczorów. W tym samym czasie napisałbyś wiele linii kodu w C korzystających wprost z istniejącej biblioteki.

Link do komentarza
Share on other sites

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.