Quick-fix for library's problems in Z-Uno?

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
Rogga10000
Posts: 10
Joined: 13 Nov 2016 21:05

Quick-fix for library's problems in Z-Uno?

Post by Rogga10000 » 22 Nov 2016 00:24

Hi Z-wave-enthusiasts,

I have an idea that I don't know if it’s possible. I understand that it’s not possible to install the libraries to Adafruits NeoPixels (WS2812) and MCP 4725 (DAC) in Z-Uno at the moment.

I need MCP 4725 to be able to control an heat pump through a variable output voltage (0-5V). Is it possible to add up a dimmer-sketch in Z-UNO that sends a digital value (0-255?) via I2C to Adafruit Trinket Pro (5V) where the 4725-library is installed? Trinket sends instructions (12-bit) via I2C to MCP4725. Maybe Z-Uno acts as a master and Trinket and MCP4725 as slaves, all with different I2C-addresses on the same I2C-bus.

I am an electrician not a programmer. Can it work as a quick-fix solution? If yes, any ideas how the sketches for Z-UNO and Trinket should look like?

Thanks in advance
Rogga

mdietinger@gmail.com
Posts: 39
Joined: 12 Aug 2016 12:08

Re: Quick-fix for library's problems in Z-Uno?

Post by mdietinger@gmail.com » 22 Nov 2016 11:01

Hello,

you don't need to go via another microcontroller to communicate with MCP4725.
I2C just works fine and if you address the chip directly without going via a library you shouldn't have any issues.
Below code I found on the web and it addresses the I2C interface directly.
Not sure whether you need to go up to 5V, but if 3.3V max Voltage is sufficient you can even spare the MCP4725 and connect to one of the PWM pins.
The code below should give you an idea how to talk to MCP4725 using I2C directly.
Together with data sheet you should get an idea what value equals to which voltage.


https://forum.arduino.cc/index.php?topic=69756.0

Code: Select all

/*
Using the Sparkfun Breakout Board for MCP4725 I2C DAC

this link made me understand how to use MCP4725 digital to analog converter
http://blog.michaelbparks.com/2008/09/sparkfun-dac-breakout-board-tutorial_8918.html


DAC MCP4725  values 0 - 4095;  0 - 5 volts

byte Device = 96;  //= binary 1100 000 = (MCP4725 device code) & A2 & A1 & A0
factory sets A2 & A1 to 0 & 0, we can set A0 to 1 or 0
A0=0 if connected to Ground, A0=1 if connected to Vdd

Stephan Schulz / www.maybevideodoes.de   /  27/03/2009
*/


byte Program = 64;
byte Device = 96; // This hardwired into the IC and the BoB, in other words, it is a given.

int maxValue = 1570; // 1570 is the max output for my project but can go up to 4095

int minValue = 0;
int value = minValue;
int dir = 1;

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("i2c");

}

void loop()
{

  byte b1 = byte((value / 16));
  byte b2 = byte(value % 16);

  Wire.beginTransmission(Device);
  Wire.send(Program);
  Wire.send(b1);
  Wire.send(b2 << 4); // Needed twice, since the 4 lowest bits (of 12) are in the fourth byte
  Wire.endTransmission();


  value = value + dir;
  if(value > maxValue) dir = -1;
  if(value < minValue) dir = 1;

  delay(5);
}

michap
Posts: 323
Joined: 26 Mar 2013 10:35
Contact:

Re: Quick-fix for library's problems in Z-Uno?

Post by michap » 22 Nov 2016 12:50

Hi,

I made a quick check of the lib of MCP4725.
You already have tried to include this lib? I think it can work.

Do not have such a module here for testing.
I have modified the bibraries so that it will be compiled without errors.

Unzip it and copy it to the local arduino library directory (like this):
C:\Users\[your name]\AppData\Roaming\Arduino15\packages\Z-Uno\hardware\zw8051\2.0.6\libraries
ZUNO_MCP4725.zip
MCP4725 lib for testing for Z-Uno
(1.95 KiB) Downloaded 131 times
You can use this sketch for testing:
test_MCP4725.zip
Arduino test for MCP4725
(600 Bytes) Downloaded 108 times
I think it will be more effective to use a direct connection... ;)

As I told before - I could not test it, have no such module here ;)

Michael

Rogga10000
Posts: 10
Joined: 13 Nov 2016 21:05

Re: Quick-fix for library's problems in Z-Uno?

Post by Rogga10000 » 26 Nov 2016 10:35

Thank you very much. It works great

/Rogga

User avatar
PoltoS
Posts: 4954
Joined: 26 Jan 2011 19:36

Re: Quick-fix for library's problems in Z-Uno?

Post by PoltoS » 26 Nov 2016 12:46

@michap Great! If you make a pull request we can include it to Z-Uno package with next release.

@Rogga10000 WS2812 is a pretty complex lib written partially on Assembler due to very strict timings. Even with our lastest changes with fast pins (http://z-uno.z-wave.me/Reference/s_pin/) it is not possible to write such a lib for Z-Uno. May be at some point we will write it in Assembler, but that will require a lot of work and is underprioratized.

Post Reply