B4R Question problem with rwire

Michael1968

Active Member
Licensed User
Longtime User
Hi all,

I have a Probleme to get I2c (ADS1015, SHT30,MCP) running with the rwire lib
I use it with a wemos mini.
I think there ist a Probleme with initalize I2c on the Wemos board
the arduino example all working.

the b4r oled example is working fine.

the same Programm is running on an other arduino Device without problem

any idea ?

thx michael
 
Last edited:

Michael1968

Active Member
Licensed User
Longtime User
Hi Erel,
the I2c Scanner example from RWblinn is working with all Arduino but not with wemos.

This Code is not working with wemos too, i can not get a Register value .

the only example is running on a wemos is the rADAFRUITSSD1306 lib.


B4X:
' B4R  Example I2C SHT30 Digital Temperatur & humidity Sensor
' Measure in regular intervals (5secs) the Temperatur & humidity and display in a line chart.
' ''''Additional Libraries: Things v1.01 (or higher)
' ''''Wiring
' 
'dev_addr = 0x45
'https://www.wemos.cc/sites/default/files/2016-11/SHT30-DIS_datasheet.pdf


#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
   
   
   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private d1pins As D1Pins
    Public wifi As ESP8266WiFi
    Public wire As WireMaster
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Log("Connected: ",wifi.Connect("test")) 'change as needed
   
    wire.Initialize
    'wire.WriteTo(0x45, Array As Byte(0x01,0x03,0xc3))
    'Delay (100)' verzögerung Messung
    DelayMicroseconds(100)
    wire.WriteTo(0x45, Array As Byte(0x2c,0x06))
    DelayMicroseconds(700)
    Dim b() As Byte =wire.RequestFrom(0x45,6) 
    Log (b(0))
   
End Sub
the same Probleme is with a ADS1015 device.
with the adafruit Arduino lib the ADS1015 is running perfect.
B4X:
include <Wire.h>
#include <Adafruit_ADS1015.h>
 
Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */
 
void setup(void)
{
  Serial.begin(9600);
  Serial.println("Getting single-ended readings from AIN0..3");
  ads.begin();
}
 
void loop(void)
{
  int16_t adc0, adc1, adc2, adc3;
 
  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  Serial.print("AIN0: ");
  Serial.println(adc0);
  Serial.print("AIN1: ");
  Serial.println(adc1);
  Serial.print("AIN2: ");
  Serial.println(adc2);
  Serial.print("AIN3: ");
  Serial.println(adc3);
  Serial.println(" ");
 
  delay(1000);
best regards
Michael
 
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
it seems to be a Problem with the rESP8266wifi lib.

I tested the Code on a Arduino again and it works...so rwire lib is OK.

has anyone same Probleme with esp8266 and i2c ?

Adafruit huzzah and nodemcu not running too.

I2C with lua or Arduino on the ESP8266 there is no problem
 
Last edited:
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
the I2c Scanner example from RWblinn is working with all Arduino but not with wemos.

Just checked if the I2C Scanner also runs for ESP8266:
Tested successfully the I2C Scanner Example on an (old) WeMOS D1 with an Adafruit BMP280 (I2C) connected.

Wiring
B4X:
BMP280 = WeMOS D1
3.3v = 3.3v
GND = GND
SCK = D3 (SCL)
SDI = D4 (SDA)

Output
B4X:
I2C device found at address: 0x77 (119)
 
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
OK next step...
if I run this Code:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300

#End Region


Sub Process_Globals
    Public Serial1 As Serial
    Public Wire As WireMaster
    Private wireerror As Byte = 0
    Private deviceaddress As Byte
    Private ctemp As Byte
   
End Sub

Private Sub AppStart
    Serial1.Initialize(9600)
    Wire.Initialize
    Scanning
End Sub

Private Sub Scanning
    Private bc As ByteConverter
    Dim b(1) As Byte
    Dim devices As Int

    Log("Scanning started...")
    devices = 0
    For i = 0 To 127
        deviceaddress = i
        RunNative("icwirebegintransmisson", deviceaddress)
        RunNative("icwireendtransmisson", Null)
        b(0) = deviceaddress
        If wireerror = 0 Then
            Log("I2C device found at address: 0x", bc.HexFromBytes(b), " (", deviceaddress, ")")
            devices = devices + 1
        End If
        If wireerror = 4 Then
            Log("I2C device unknown at address: 0x", bc.HexFromBytes(b), " (", deviceaddress, ")")
        End If
    Next
    If (devices = 0) Then
        Log("No I2C devices.")
    End If
    Log("Scanning completed.")
   
    '------------------------------------------------------------------------------------------
    'get the temperature for SHT with inline C *****WORKS *********** !!!!!!
    RunNative("sht", Null)
    Log (ctemp)
   
'    ---------------------------------------------------------------------------------------
    Wire.WriteTo(0x45, Array As Byte(0x2c,0x06))
    DelayMicroseconds(500)
    'Dim c() As Byte =Wire.RequestFrom(0x45,6)
'    Log (c(0))
'    Log (c(1))
'    Log (c(2))
   
End Sub

#if C
#include <Wire.h>
void icwirebegintransmisson (B4R::Object* o) {
  Wire.beginTransmission(b4r_main::_deviceaddress);
}

void icwireendtransmisson (B4R::Object* o) {
  b4r_main::_wireerror = Wire.endTransmission();
}

void sht (B4R::Object* o) {
     unsigned int data[6];
   
    Wire.beginTransmission(0x45);
      Wire.write(0x2C);
      Wire.write(0x06);
    Wire.endTransmission();
    delay(500);
    Wire.requestFrom(0x45, 6);

    // Read 6 bytes of data
    // cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc
    if (Wire.available() == 6)
    {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
    }
    b4r_main::_ctemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
}

#End if

I get this LOG:
�H�I�E�lؤ~YH��Scanning started...
I2C device found at address: 0x00 (0)
I2C device found at address: 0x3C (60)
I2C device found at address: 0x45 (69)
Scanning completed.
26
Code works
if I uncomment line 57 I get this Error:

I2C device unknown at address: 0x0D (13)
I2C device unknown at address: 0x0E (14)
I2C device unknown at address: 0x0F (15)
I2C device unknown at address: 0x10 (16)
I2C device unknown at address: 0x11 (17)
I2C device unknown at address: 0x12 (18)
I2C device unknown at address: 0x13 (19)
I2C device unknown at address: 0x14 (20)
I2C device unknown at address: 0x15 (21)
I2C device unknown at address: 0x16 (22)
I2C device unknown at address: 0x17 (23)
I2C device unknown at address: 0x18 (24)
I2C device unknown at address: 0x19 (25)
I2C device unknown at address: 0x1A (26)
Exception (3):
epc1=0x401003e9 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40010899 depc=0x00000000
ctx: sys
sp: 3ffffd40 end: 3fffffb0 offset: 01a0
>>>stack>>>
3ffffee0: 00000000 3fffdad0 3ffee6bc 00000030
3ffffef0: 401057dc 0006fc76 3ffed6e0 00000000
3fffff00: 401063bc 00000000 00000064 401004d8
3fffff10: 3ffee5e4 0000000f 0000000f 401074c8
3fffff20: 3ffefbe8 3ffefbe4 0006b749 402230a5
3fffff30: 3ffefbe8 3ffefbe4 0006b749 401063d6
3fffff40: 3ffede90 0015895d 60000600 402232ed
3fffff50: 401063bc 00000000 3ffede90 0015895d
3fffff60: 40219f0c 3ffede68 3ffede90 60000600
3fffff70: 0015e810 3ffede90 3ffede68 40219f19
3fffff80: 40219f5e 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffedeb8 3fffdad0 3ffee6bc 40203787
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<

is it a Stack Problem? how can explain it to me ?
I'm search now for 2 days to get rwire running on a wemos d1 mini.

THX

Michael
 
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
the C Code gives me the correct Byte.lenght (6).

B4X:
Dim c() As Byte = Wire.RequestFrom(...)
If c.Length >= 6 Then ...

End If

return 0
 
Upvote 0
Top