-
• #2
Hi @jameslouiz
with the Espruino implementation for ESP8266 you can use I2C1, which is a c-code implementation of a I2C master
I2C1.setup({ scl: NodeMCU.D2, sda: NodeMCU.D1 }); // read I2C1.readFrom(address, quantity); // write I2C1.writeTo(address, data, ...);
Maybe you like to check some modules using i2c to get a better understanding for I2C on this page.
You can also try the Espruino servo motor module .
-
• #4
You should try one of these i2c device scanner to be sure about your wires and pullup resistors are ok. If the list does not show your device, start checking used pins and cable. Or maybe you are just using the wrong address ;-)
-
• #6
I get I2CWrite: No ACK 0 when trying
i2c.writeTo(n, 1000)
where n is an integer between 0 and 200. I assumed it would work on channel 1-16? -
• #7
I've tried some code @Gordon posted a few weeks ago but don't seem to be having any luck with that either :/
var C = { PCA9685_SUBADR1 : 0x2, PCA9685_SUBADR2 : 0x3, PCA9685_SUBADR3 : 0x4, PCA9685_MODE1 : 0x0, PCA9685_PRESCALE : 0xFE, LED0_ON_L : 0x6, LED0_ON_H : 0x7, LED0_OFF_L : 0x8, LED0_OFF_H : 0x9, ALLLED_ON_L : 0xFA, ALLLED_ON_H : 0xFB, ALLLED_OFF_L : 0xFC, ALLLED_OFF_H : 0xFD }; function PWMServoDriver(i2c) { this.i2c = i2c; this.addr = 0x40; this.reset(()=>{ this.setPWMFreq(1000); }); } PWMServoDriver.prototype.write = function(r,d) { this.i2c.writeTo(this.addr,r,d); }; PWMServoDriver.prototype.read = function(r) { this.i2c.writeTo(this.addr,r); return this.i2c.readFrom(this.addr,1)[0]; }; PWMServoDriver.prototype.reset = function(callback) { this.write(C.PCA9685_MODE1, 0x80); if (callback) setTimeout(callback,10); }; PWMServoDriver.prototype.setPWM = function(num,on,off) { this.i2c.writeTo(this.addr, C.LED0_ON_L+4*num, on, on>>8, off,off>>8 ); }; PWMServoDriver.prototype.setPWMFreq = function(freq) { // "Sets the PWM frequency" var prescaleval = 25000000.0; // 25MHz prescaleval /= 4096.0; // 12-bit prescaleval /= freq; prescaleval -= 1.0; prescale = Math.floor(prescaleval + 0.5); var data = this.i2c.readFrom(C.PCA9685_MODE1, 1); var oldmode = data[0]; var newmode = oldmode & 0x7F | 0x10; // sleep this.i2c.writeTo(C.PCA9685_MODE1, newmode); // go to sleep this.i2c.writeTo(C.PCA9685_PRESCALE, Math.floor(prescale)); this.i2c.writeTo(C.PCA9685_MODE1, oldmode); setTimeout(() => { return this.i2c.writeTo(C.PCA9685_MODE1, oldmode | 0x80); }, 5000); }; const connect = function(i2c) { return new PWMServoDriver(i2c); }; setTimeout(() => { var i2c = new I2C(); // software I2C i2c.setup({sda:NodeMCU.D1, scl:NodeMCU.D2}); var pwm = connect(i2c); pwm.setPWMFreq(60); var SERVOMIN = 150; var SERVOMAX = 600; setInterval(() => { for (let pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) { pwm.setPWM(0, 0, pulselen); } }, 1); }, 200);
-
• #8
each number is a i2c address of a device. Looks like you have two devices attached to this bus, a device with address 64 and another with 112.
Use this address as first parameter for writeTo and readFrom.
The code above is using Espruino i2c software solution and is talking to a device address 0x40 which is 64 decimal.
Looks like you are not using this.read() eg in line 48 and this.write() eg in line 53 in the code. changing this in all lines might solve the issue.
-
• #9
My I2C instance is currently using 0x40 (64) for the address but I'm not sure what address I should use for channel 0 in the
i2c.writeTo(address, data)
method. -
• #10
this is what I mean
sample for line 48
var data = this.i2c.readFrom(C.PCA9685_MODE1, 1);
to
var data = this.read(C.PCA9685_MODE1, 1);
Hi all, I have no idea how to get my PCA9685 to respond to any kind of input from my NODEMCU ESP-12E. I know both boards work as I've already tried with a program written in C.
For now, all I'm trying to do is make a single servo move on channel 0, here is my code. You might notice its pretty much just the Adafruit library with a few modifications. Nothing seems to happen with the servo :/