I2C in arduino

Hi, I am trying to connect two arduino UNO together. Lets call one U1 and the other U2. U1 is master and U2 is slave. Now I want to attach a wave shield to U2 which is slave and operate it from U1. Is that possible? If it is possible, then can I use any pin to transmit and receive signal?? Cause in some forums they say that I2C is done by using digital pin 4 and 5. However, these pins are taken by wave shield. So please help me out in this.

Topic by Bam Boy 6 years ago  |  last reply 4 years ago


Rspberry PI I2C message control through Web portal

I need help to build web page which can control devices connected to raspberry pi through I2c . For example if i connected some DAC IC with raspberry pi . i i should able to adjust that DAC value from web. Please help us

Topic by Logen 4 years ago  |  last reply 4 years ago


Help... PCF8574T (Expanding "Nano's" Digital Outputs)

- When I saw my RGB Chromatograph clock my teacher built from a kit  I was so impressed with it I  jumped the gun & ordered the parts so I could make one with an arduino version, I never thought much about it, thats so simple I could do in a few hours no problem except I overlooked one simple thing.... This clock uses six 10mm RGB Leds, two for the hour, two for the minutes & two for the seconds, each led has 3 inputs & 1 ground, thats a total of 18 outputs,  thats not including a few other inputs used for status indicators, along with a few inputs for buttons, the problem is that a Nano doesnt have enough digital outputs & I completely overlooked that fact. Anyways I started looking for I/O expanders when I realized that I have a few 1602 displays & PCF8574T backpacks, I have heard some people claim that it can be used to provide an additional 16 digital outputs, if true then it that would resolve my issue very easy Has anyone done this? or example sketch how I could deploy the PCF8574 this way, for example a blink sketch that defines a pin on the PCF8574 as an outputs & turns on a LED connected to the pin Thank you much...

Question by rdlockrey 2 years ago  |  last reply 2 years ago


Glitchy I2C LCD (lines on the display)?

So, I am working on a little project with an Atmega328 and an 16x2 LCD. I have it wired up and when I went to test it with the "hello world" example, The LCD does work, but there are random lines on the display..  It's not the contrast or the code, and I checked the connections and it all seems ok. What might be causing my problem? 

Question by Dashing Rainbow Dash 3 years ago  |  last reply 3 years ago


I2C addresses > 63 are not usable with atTiny85?

Hi I have a big problem with addressing multiple attiny85-chips with I2C: For what I know the attiny uses 7-bit addresses for communication. I am using the TinyWireS lib, which works perfectly fine for me, untill I am reaching address: '64' which is '1000000' in binary. The highest usable address should be '1111111'. Here is the attiny85 datesheet. This is what happens: Slave: Attiny85: switches led on or off when msg is received over I2C. Slaveaddress: 64 #include #include #define output (4) #define I2C_SLAVE_ADDR (64) //works if I2C_SLAVE_ADDR < 64 void setup() {   TinyWireS.begin(I2C_SLAVE_ADDR);   pinMode(output, OUTPUT); } volatile bool state = LOW; void loop() {   byte msg = -1;   if(TinyWireS.available())     msg = TinyWireS.receive();   if(msg == 1)     state = HIGH;   else if(msg == 0)     state = LOW;   else if(msg == 2)     state = !state;   digitalWrite(output, state); } Master: Arduino pro mini: sendMsg(0, true); //works! led on chip: 64 switches on sendMsg(64, true); //fails! led on chip: 64 is off. #include #define DEVICE (64) //0 works! void setup() {     Wire.begin(); } void loop() {     sendMsg(1, DEVICE);     delay(2000);     sendMsg(0, DEVICE);     delay(2000); } void sendMsg(int msg, int device) {     Wire.beginTransmission(device);     Wire.write(msg);     Wire.endTransmission(); } Have you any idea how to solve this problem?

Question by DELETED_MakiY2 1 year ago  |  last reply 1 year ago


I2C to SPI BASIC code conversion?

 Hello all. Pretty daft and most likely simple sollution to those who know what they are doing I'm sure. I am building a 132 LED clock (60 for seconds, 60 for minutes and 12 for hours). I'm using a Picaxe 28X2 and will most likely be using 3 MAX7221's to display the LED's, 1 each for the hours, minutes and seconds. I'm currentlty using a DS1307 RTC module to keep time. Exposition over!  My question is, I am using open source code from a guy who made a clock using Pic 28X1, MAX7221 and DS1305 displaying on four 7-segment displays. now the differences between the Pic's with regard to coding I can handle, although I do have a 28X1. The fact that the DS1305 and 1307 use SPI and I2C respectively means that the differences between comms protocols are confusing the hell out of me.  Now please forgive the length of this question. Basically, I need some pointers as to whether it would be better to try and convert the code to use I2C for the RTC and stick with SPI for the MAX or should I just buy a DS1305 at almost £6 per chip and make my life a bit easier? I have already tried using the code with my 1307 but the 7-seg display I have just stays on the No2.  As for the differences in display type...well I'll come to that once I get the timing working.  If I've left anything out or you need more information then please let me know.  Here is the link to the clock schematic: http://tech-tut.com/wp-content/uploads/2008/08/real_time_clock_advanced_schematic.pdf    And the code is far too long to be pasted here I'm affraid and the file I originally got it from had converted it into word which pushed all the lines together. That was a fun few hours sorting that out! Thanks in advance

Question by LED Maestro 5 years ago  |  last reply 5 years ago


How to read uart data and write to i2c device.

// Port for the I2C #define I2C_DDR DDRD #define I2C_PIN PIND #define I2C_PORT PORTD // Pins to be used in the bit banging #define I2C_CLK 0 #define I2C_DAT 1 #define I2C_DATA_HI()\ I2C_DDR &= ~ (1 << I2C_DAT);\ I2C_PORT |= (1 << I2C_DAT); #define I2C_DATA_LO()\ I2C_DDR |= (1 << I2C_DAT);\ I2C_PORT &= ~ (1 << I2C_DAT); #define I2C_CLOCK_HI()\ I2C_DDR &= ~ (1 << I2C_CLK);\ I2C_PORT |= (1 << I2C_CLK); #define I2C_CLOCK_LO()\ I2C_DDR |= (1 << I2C_CLK);\ I2C_PORT &= ~ (1 << I2C_CLK); void I2C_WriteBit(unsigned char c) {     if (c > 0)     {         I2C_DATA_HI();     }     else     {         I2C_DATA_LO();     }     I2C_CLOCK_HI();     delay(1);     I2C_CLOCK_LO();     delay(1);     if (c > 0)     {         I2C_DATA_LO();     }     delay(1); } unsigned char I2C_ReadBit() {     I2C_DATA_HI();     I2C_CLOCK_HI();     delay(1);     unsigned char c = I2C_PIN;     I2C_CLOCK_LO();     delay(1);     return (c >> I2C_DAT) & 1; } // Inits bitbanging port, must be called before using the functions below // void I2C_Init() {     I2C_PORT &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));     I2C_CLOCK_HI();     I2C_DATA_HI();     delay(1); } // Send a START Condition // void I2C_Start() {     // set both to high at the same time     I2C_DDR &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));     delay(1);     I2C_DATA_LO();     delay(1);     I2C_CLOCK_LO();     delay(1); } // Send a STOP Condition // void I2C_Stop() {     I2C_CLOCK_HI();     delay(1);     I2C_DATA_HI();     delay(1); } // write a byte to the I2C slave device // unsigned char I2C_Write(unsigned char c) {     for (char i = 0; i < 8; i++)     {         I2C_WriteBit(c & 128);         c <<= 1;     }     //return I2C_ReadBit();     return 0; } // read a byte from the I2C slave device // unsigned char I2C_Read(unsigned char ack) {     unsigned char res = 0;     for (char i = 0; i < 8; i++)     {         res <<= 1;         res |= I2C_ReadBit();     }     if (ack > 0)     {         I2C_WriteBit(0);     }     else     {         I2C_WriteBit(1);     }     delay(1);     return res; }

Topic by Blixxer 4 years ago  |  last reply 4 years ago


Does anybody know if the sensors from off brand wiimote cameras work with ardunio?

I've  been looking everywhere for a cheaper infrared camera.

Question by wkuace 9 years ago  |  last reply 9 years ago


Electronic Toolkit

I do some work with the FIRST Robotics kids and it is amazing to see what they are doing.  Big problem though seems to be a general lack of electrical test equipment.  They don't really have the money to buy oscilloscopes, function generators, CAN and I2C analyzers.   So I got one of the M3 Discovery boards from STmicro and it is really cool.  It has four 5MS A/Ds on it plus a whole host of other features(CAN, I2C, Serial etc.). http://www.st.com/web/en/catalog/tools/PF254044 So it got me thinking. Why couldn't we turn one of these chips into an "All-In-One" electrical toolkit and keep it cheap($50-$60, BOM ~$20).  It would be fairly easy to turnkey. I threw together some simple specs, what do people think. 1) Will supply general use drivers so a user can use the app or write their own. 2) Oscilloscope   a. Two Channel     i. 2MHZ of Analog Bandwidth per channel     ii. 10MS/s per channel     iii. Trigger on rising edge, falling edge, on-command, run-stop actions     iv. Datalogging for extended time periods at up to 10hz per channel (data stored directly to console),  maybe higher rate will  just have to see 3) Serial – 2 Ports   a. Multi selectable protocol w/slew control     i. RS232, RS422, RS485 4) CANBus – 1 port 5) I2C – 1 port 6) SPI  - 1 port 7) 8 Discrete User Selectable 8) Function Generator   a. Two Channel      i. 1MS/s small signal change      ii. 250kS/s full range change      iii. 0-3.3VDC buffered output  9) PWM - 4 Channels

Topic by ase4542 4 years ago  |  last reply 4 years ago


how do use i2c on arduino with out pull-up ?

Question by act casual 7 years ago  |  last reply 7 years ago


Integrating a sensor to arduino?

I want to know to integrate a sensor to arduino. I mean how to start and from where to start. I dont want to use existing libraries, I want to create my own. I know the working of sensors and and some other basic stuff.  I want to read a sensor data (for ex: ADXL345), I want to look into the datasheet and implement it. Please someone help in starting

Question by naveenkumarmn7 4 years ago  |  last reply 4 years ago


Are there any ammonium sensor for salt water with I2C interface?

Hi, I am a newbie to anything electronic.I am trying to design an array of sensors for a salt water aquarium. I have found the DO and pH sensors from Atlas, now I need a temperature and ammonium sensor for the salt water tank, all with I2C interface.Does anyone out there know of any they can recommend?

Question by achaninau 1 year ago


Export integer from arduino to processing?

How can I take an integer or float value from an arduino, and put it into processing over serial (usb), without changing it to a char or something else?  It needs to be fairly fast (within ~1/8 sec), and be able to be converted to an audio tone.  Also, how can I play an audio tone in processing?  I looked on the reference page, and couldn't find any documentation on just a basic square or sine wave output of variable frequency (except the example, which uses something weird). 

Question by jduffy54 6 years ago  |  last reply 6 years ago


Building Audio System, Have Questions About ICs? Answered

So as the title states I want to design an audio system, I purchased an old shortwave radio someone gutted, but the case is in great shape and looks really cool, would make a killer looking amp.  So a little background, I want to make a stereo amp I can hook up several inputs to and my speakers; likely a turntable, iPod, radio, and whatever else I feel like.  The radio came with a nice little 5 position rotary switch for that.  The main problem I am facing is what ICs I want to use, and what order.  I have not dealt much with audio and at first I thought of buying a radio and just putting the guts into this unit, but I thought this would be a good project to dive into audio work.  You can't learn if you don't push your bounds a bit, am I right? The first IC question is about chips like the PT2322.  There are several I have looked at that use a microcontroller for control, and I am not against using an Arduino Micro in this unit, but I am unsure of how the acknowledgment bit works.  The data input seems to just be a shift register, data gets clocked in, then latched.  Data is fed in in 8 bit strings, but then it mentions an acknowledgement bit as a 9th bit.  Is this bit for the latch, or is there a 9th bit fed in before everything is latched?  Should it be hi or lo?  As well I was looking at the commands, several commands have 7 of their 8 bits written as a *, does this mean that those bits can be set hi or lo?  I am sure these aren't difficult questions and I glossed over something important in one of the many data sheets, and that I do not use these chips with any regularity, if ever, doesn't help either!  But I like that these ICs all seem to have a 3 band tone control and volume control built into them. If I were not to use an IC controlled by a microcontroller, I am looking at using a BA3812 for the tone controls, 5 band is a little more then I need, I really only wanted 3, not 2 but not more then 3.  Bass, treble and mid range.  But I could not find a 3 band IC without microcontroller inputs required for operation, and it was not for the lack of trying.  I can handle 5 bands though, however I am wondering, should I go preamp to equalizer to the main amp, or where would I wire in the BA3812?  This seems like a stupid question to me, I feel like an audiophile is going to come along and say, "You never put the equalizer after the preamp, it always goes here or there!" or something along those lines.  As well, regardless of where its going to get wired in, since I am doing stereo not mono, I assume I will need 2 BA3812's, but the datasheet supplies a circuit for 3 Chips as well.  Which would be suggested, 2 or 3?  I am wanting to control both left and right tone controls together, so using 5 pots instead of 10, and would also like to be able to have a balance control.  I didn't see anything about balance control in the BA3812 datasheet, would there be a good way of accomplishing that with these ICs or the use of a couple op amps maybe?  I didn't really look into balance, I should have before asking questions. For the preamp the LM1036 seemed like a good choice.  I was reading into preamps, and they seem more important for the turntable then anything else.  The way the grooves on a record are cut they boost the high frequencies so they don't fade awayat lower volumes or something like that.  Because of that a preamp that boosts bass and cuts treble is useful and improves sound quality when using turntables.  Should I use a preamp only for the turntable input or for all inputs?  If I adjust the equalizer for records is a preamp necessary or should I use the preamp and set it with trim pots to boost bass and cut treble a little, or should it be fully adjustable as well? As far as what to use for the final amplification I am at a bit of a loss.  A home theater system I have is 1500W and is adequately loud, but the system I have for my turntable right now think is only 250W I believe and it seems louder.  Never really understood wattages for "loudness"  or output on sound system.  I saw an IC (can't remember number, its a TDA though) dual 50W amplifier.  Not sure if 50W for each channel would be enough.  Advice would be helpful. As a side note, if I do go the route of a microcontroller, I found this NJW1186 with stereo input and 5.1 surround output which I thought would be cool. I really appreciate any help. Thank you

Question by KlockWork 4 years ago  |  last reply 1 year ago


Can the LP3943 source current as well, or only sink it? Answered

The link to the data sheet is here. All it talks about is sinking current, so my guess is yes.  I really wanted to use two of these to get a huge multiplexed array of LEDs, but one of them would need to be able to source the current, can it with the pins set high?  If not, are there other ICs like this that can do so? Thanks!

Question by mojofilta 7 years ago  |  last reply 7 years ago


can i use the S-3530A RTC with an arduino (no luck for i2c address from datasheet)? Answered

I found this rtc in a printer and i am having trouble setting the time on it. i would like to use it in place of a DS1307 but i dont know the i2c address of it ir how to set the time on it,. ANY help would be appreciated. datasheet: http://vk5bbs.ampr.org/pages/techdata/data/RTC/s3530a.pdf

Question by devicemodder 5 years ago  |  last reply 5 years ago


Connection Winstar WH1602B3-SLL-JWV 16x2 LCD VATN White on Black I2C Interface to Arduino UNO

Hello,I have some trouble with the connection of the Winstar I2C LCD to a Arduino Uno.Can someone advise me?In a pdf from Winstar there is a diagram (as attached), but I see a lot af pins that I don't know how to connect to a Arduino.Thank you very much for your help.Roland

Question by rolandzu 7 months ago  |  last reply 19 days ago


What are some low power displays for arduino communication?

I need a display that could show at least the date and/or time for an arduino clock.  I am looking for the one with the lowest power consumption possible, perhaps the kind found on digital watches?  (I don't know what those are called)  if possible the display should have spi or I2C communication, preferably I2C.   Any help would be awesome! Thanks  ~Dudes

Question by dudes 3 years ago  |  last reply 3 years ago


How to add a memory function when I push a button

I have a proyect with a MLX90614 (an ir infrared thermometer with I2c), and the output temperature is displayed in a oled 128x64 I2c, I am using an arduino pro mini, the code works well, but i want to add a function: I want to press a button that saves the temperature shown, in the right down corner of the screen, and if I press it again to save again the temperature. It is like a memory function, I searched on the internet and I discovered that there is a memory in the arduino called eeprom but i have problems combining that function with the code. Any help appreciated. Thanks. Code: #include "U8glib.h"            // U8glib library for the OLED #include               // Wire library for I2C communication #include // MLX90614 library from Adafruit Adafruit_MLX90614 mlx = Adafruit_MLX90614(); U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C void draw(void) {   u8g.setFont(u8g_font_profont15r);        // select font   u8g.drawStr(1, 12, "Object Temperature");//   u8g.setFont(u8g_font_profont29r);        // select font for temperature readings   u8g.println("°C");                        // prints C for Celsius   u8g.setPrintPos(35, 55);                 // set position   u8g.println(mlx.readObjectTempC(), 0);   // display temperature from MLX90614 Serial.println(mlx.readObjectTempC(), 0); // u8g.drawRFrame(15, 20, 100, 30, 10);     // draws frame with rounded edges } void setup(void) {   Serial.begin(9600);     mlx.begin();  //Receive data from the sensor } void loop(void) {   u8g.firstPage();    do     {      draw();          }   while( u8g.nextPage() );     delay(1000);  // Delay of 1sec }

Question by tmercados 1 year ago  |  last reply 1 year ago


Daft Punk Table Replica driver board reverse reconstruction.

I'm in love with the daft punk table: https://www.instructables.com/id/How-to-build-a-Daft-Punk-Table-Replica/?ALLSTEPSI'm actually making a wall hanging rather than a table because theres no room in my studio for another table.The author of that instructable didn't include the microcontroller program or a circuit for the driver board. From the description (and looking at another site) we can tell that it uses a a couple I2C port expanders connected to a transistor array. I have both the PFC port expander and the ULN2803A in my parts box, but I think it can be made cheaper, faster, and expandable.I want to ditch the I2C bus. Why? 1. Its slow (100 or 400 khz), not that more is needed, but what about bigger boards?2. Its bit intensive: each chip update requires a)start signal, b) address byte, c)port setting byte, d)stop signal. That's more than 8 bytes of bits per table update.3. Its expensive: the i2c bus needs 2 pullup resistors, and you have to route Vcc to them on the PCB. I2C peripherals are a bit pricey ($1+ for the PFC i2c port expander). You need a UC with hardware I2C, or write a I2C software routine, etc. 4. Its not expandable beyond the assigned number of I2C addresses. The PFC chips have a limited number of address selections (determined by the state of 3 pins). If all addresses have been used then a second I2C bus would have to be added.These goals can all be accomplished with a handy chip I learned about in lady ada's bike POV instructable, the 74HC(T)595. The 595 is a serial to parallel port expander with 8 output bits. The interface is a simple 3 line affair with serial data/clock lines and a latch that puts the data on the pins. Now the cool part: several can be connected end-to-end so that you can create a chain with hundreds of extra outputs. Bits can be clocked in at up to 20Mhz, so large or multiplexed grids are possible.Why its good:1. Its fast, up to 20 Mhz2. Simple interface - clock in only the bits needed then set the latch. 26 bits, <4 bytes per refresh.3. Its cheap: 0.33 per chip, easy 3 wire interface can be operated with microcontroller, PC parallel port, or even buttons.4. Massively expansion potential, multiple chips can be chained for a disgusting number of outputs.The circuit is pretty basic. It only includes those things needed for the graphics card : I/O expanders, transistor array, connection headers. Power supply and control unit are separate components. The 595 has a 'blank' pin, it seems to reset all the chips to a known state when pulled low. I wanted to make it available for a 'more complete' design, but I also included a jumper so that it can be manually disabled for use in simpler implementations.The 3d is just for fun: the PCB is mostly unrouted.Any comments or suggestions? Has anyone used the 595 before? I've ordered a few to play with, but have not yet used them.

Topic by ian 11 years ago  |  last reply 10 years ago


Can anyone please give me code to detect speed and display on LCD using I2C interface?

   I have a speed sensor which gives 8 pulse per revolution of wheel. I want to calculate the speed of the wheel and display it on an LCD using I2C interface. The LCD interface works fine and I can print anything on it. But I do not know the code to calculate the speed and display it on LCD.   Please help me and share with me a code that will calculate the speed based on 8 pulses/rev and display the speed on my LCD.

Question by edifiedsprit 6 years ago  |  last reply 6 years ago


using 2 x adafruit motor shield v2 in MATLAB

Hi, I set up an Arduino + adafruit motor shield v2 to control 4 x DC motors in a robot arm via MATLAB, which work fantastic. I mounted the robot arm on a 4WD base (each wheel has a separate DC motor), so now I have additional 4 more DC motors to control. I know the adafruit motor shield v2 is stackable, as long as you solder the I2C part on the second shield. I don't know if MATLAB supports 2 x adafruit motor shield v2 on top of Aurduino (2nd shield via I2c), to control 8 DC motors in total any advise or experience is highly appreciated

Question by Begginer2017 1 year ago  |  last reply 1 year ago


Is it possible to make a Beowulf Custer with Arduino?

Is it possible to make a small cluster computer using Arduinos? It has been done with Pi, but could it be made with breadboard Arduino? I read about I2C and it seems viable. Anyone had tried it yet? Awaiting some reply Trace

Question by Tanmay Das 4 years ago  |  last reply 2 years ago


S-3530A RTC and arduino

I found this rtc in a printer and i am having trouble setting the time on it. i would like to use it in place of a DS1307 but i dont know the i2c address of it ir how to set the time on it,. ANY help would be appreciated. datasheet: http://vk5bbs.ampr.org/pages/techdata/data/RTC/s3530a.pdf

Topic by devicemodder 5 years ago


LED controlling with real time clock ?

Hello I am interfacing RTC with microcontroller  and LED. actually I have prototyping KIt (cortex m0). I only need c code. I want to control LED using real time clock via I2c pins         Set alarm for 5 second (automatically turn on LED for 5 second )         Set alarm for 3 minute (automatically turn on LED for 3 minute)         Set alarm for 1 hours (automatically turn on Led for 1 hours )         SCL connected with P3.5;         SDA connected with P3.1;         LED connected with P1.6         LED will read the data form ds1307 via i2c pins I did google searched but I did not find related to LED. I am not using LCD  can someone explain with small example. How to write c code for minute , hours , day

Question by vead 4 years ago


NEED HELP im making a Robot controlled by ps3 controller! and i cany find the I2c cable ?

The robot was originaly made by nahamancygig     https://www.instructables.com/id/Use-a-PS3-Controller-to-control-an-Arduino-NXT-Bot/ If any one knows where to get the cable please tell me ASAP!!!! cos its My GCSE  ELECTRONIC project.

Question by devilmaycry 7 years ago  |  last reply 7 years ago


Two arduino nano with oled check please help

Hi friends, I connected 2 arduino with i2c data, I'm doing the classic Led flashing, my question is, the master card in the project, counting from 1 to 100 counters, and initially the green LED is lit, when the counter is 80 yellow Led lights up green and 95 when yellow turns off and turns red, the system turns off. And this whole process is being copied to the sd card, the energy is cut off and the counter continues to be nosed when it is given again. Due to lack of memory the need for the second card was born. Now the Master is also on the slave card connected to the slave when it comes to burning operations (when the green LED is lit, the "system is running" while the yellow LED is running "maintenance approached" as the "service time", etc.) did the research but did not get a result. please help

Question by ErolT3 20 days ago


how do I use the data from a ITG-3200 gyro? Answered

I have a ITG-3200 gyro on a breakoutboard from sparkfun. I got the I2C-communication working and I get a steady stream of data but I can't make anything sensible from it. Does Anyone have have experience with Gyros?

Question by janw 8 years ago  |  last reply 8 years ago


Interfacing the nxt and rfid via the ardiuno?

I am  having a problem here,I am to connect an rfid card reader to the arduino microcontroller and then the microcontroller to the nxt robot.From the researches that i have made i have learnt that the nxt communicates with the ardiuno microcontroller through I2C while the microcontroller itself reads data fom the rfid antenna using an UART bus.I am wondering if you could help on the code to make the arduino send a message to the nxt.

Question by roagile-2007 9 years ago  |  last reply 9 years ago


Does anybody know of a Potentiometer that can be set digitaly but operate passively?

I wonder if this technology exists. Imagine the following situation: During setup/calibration I can power the circuit and "tune" my potentiometer using some type of digital interface. (e.g. I2C) However, during operation the device is fully passive and will not have a source of power. Thus, the potentiometer would need to "remember" the settings and operate passively. Currently I use standard potentiometers, but tuning them manually is way too cumbersome and not practical. Ideas?

Question by Kapiau 4 years ago  |  last reply 4 years ago


Char Device Driver with Port Expansion using MCP23017?

I am new to Linux Kernel Development and I want to implement a Char device driver which handles Port expansion using a MCP23017 with a RaspberryPi (Raspbian Wheezy) using C. Here is the datesheet of mcp23017 A control for port expansion (MCP23017) is required. A less of a driver in the true sense, but more with porting functions in a driver.   The module is addressed via I2C. I need to implement the following functions in the driver: · Configuration of the I2C address · Configuration of the IOs · Configuration of Pull-Ups · Configuration of interrupts · Read / write the IOs It is important that up to 8 modules can be opened/operated simultaneously (8 is the max. possible number of addresses of the block). I have seen a number of examples in the internet and implemented a simple char device driver with init, open, read and write functions and also tested I2C operations for MCP23017. I have got a brief idea about a device driver but don't know how to further implement the functions. I would like to know/clarified about the following:     How does the dev_open work? How can I try to open a device through a linux command and check if the device is opened/ the number of times the device is opened through dmesg command?     I want 8 different modules to be opened simultaneously using the device driver and the Configuration of the MCP23017 IOs, Pullups and Interrupts. How is it done? Errors: /home/pi/i2c_gpio/mcp23017.c: In function ‘mcp23s08_direction_input’: /home/pi/i2c_gpio/mcp23017.c:269:9: error: implicit declaration of function      ‘gpiochip_get_data’ [-Werror=implicit-function-declaration] struct mcp23s08 *mcp = gpiochip_get_data(chip);      /home/pi/i2c_gpio/mcp23017.c: In function ‘mcp23s08_probe_one’: /home/pi/i2c_gpio/mcp23017.c:615:11: error: ‘struct gpio_chip’ has no         member  named ‘parent’ mcp->chip.parent = dev;                  /home/pi/i2c_gpio/mcp23017.c:681:2: error: implicit declaration of  function ‘gpiochip_add_data’ [-Werror=implicit-function-declaration] status = gpiochip_add_data(&mcp-;>chip, mcp); ^

Question by DELETED_MakiY2 1 year ago  |  last reply 1 year ago


Review of my first PCB design for a current meter shield?

I am completely new in designing circuits and PCBs and would appreciate your feedback on my first project. I want to measure the current flowing through an AC line using the ACS712 current sensor (IC1). The analog output (which is a proportional voltage between 0V and 5V) is converted using an ADS1115 (IC2). The digital signal is passed to an underlying Wemos D1 mini board via I2C, which contains an ESP8266 to process and send the data to a server. Furthermore, an AC/DC module (HLK-PM01) is mounted on the bottom side of the PCB to power the components.

Question by DELETED_MakiY2 1 year ago


Gcode for arduino

So this is an idea but also a question. so I want to make a cnc but rather then going down the conventional way I want a plug and play system. the idea is to use something like https://i.ebayimg.com/images/g/d1cAAOSwXshaQF6k/s-...the things I want to add is its own driver and nano, 2 endstops and a rotary encoder.Are Arduino nano's capable of taking g-code, sending to nema while reading an encoder and endstops?also is there a way to have on the nano a limit on movement. so it knows its length (defined by user) and then if a code comes in that will make it go past the endstop it sends error code?also this needs to run on i2c or usb and synchronise with other similiar setups for better archs and such?

Question by plucas1 1 year ago  |  last reply 1 year ago


I need a way of measuring a 0-1000kHz signal (50% duty cycle square wave from a TSL237) with an arduino. Answered

I'm willing to use external hardware if it is cheap.I've tried using an interrupt base pulse accumulator but when the frequency becomes high the counter increments so fast that it stops the arduino from doing anything else (like stopping counting). Does anyone know of a nice easy solution to count frequency? Perhaps a fancy 8 pin DIP that talks i2c? I need to be senstive to the very low end of the frequency scale too, so just throwing a prescaler on will not solve this (afaik). Thanks.

Question by quatch 6 years ago  |  last reply 6 years ago


temperature logging with raspberry pi

New here, and to Pi/Python looking to log data from a few different sensors from Atlas Scientific (RTD & PH).  I've gotten really stuck so fare in getting these going and was wondering if anyone here can help me out.  so far I've used this code:  import smbus import time import datetime #SMBus(0) - Raspberry Pi Model A #SMBus(1) - Raspberry Pi Model B bus = smbus.SMBus(1) #I2C address of sensor address = 0x66 def temperature():     rvalue0 = bus.read_word_data(address,0)     rvalue1 = (rvalue0 & 0xff00) >> 8     rvalue2 = rvalue0 & 0x00ff     rvalue = (((rvalue2 * 256) + rvalue1) >> 4 ) *.0625     #print rvalue1, rvalue2     return rvalue print("Temperature Data Logger\n") while True:         #Open Log File     f=open('tempdata.txt','a')     now = datetime.datetime.now()     timestamp = now.strftime("%Y/%m/%d %H:%M")     outvalue = temperature()     outstring = str(timestamp)+"  "+str(outvalue)+" C "+str(outvalue*1.8+32)+" F"+"\n"     print outstring     f.write(outstring)     f.close()     #log temperature every 10 seconds     time.sleep(10) I've got the two sensor boards connected to the raspberry pi 3 mounted via a Whitebox Tentacle T3.   The boards are in i2c mode and i can see them using sudo i2cdetect -y 1 (they show up address 63 and 66)  but when i run this program above I just get a red error light when it reads the temperature.   The log file reports a measurement of 2C and 35.2F which is not correct but the red light on the board tells me that the Pi is trying to connect with it.   Anyone able to help?

Topic by Chair_t 1 year ago


Arduino Serial monitor to LC

UPDATEI manage it to work, now i have a short, cross and continuity tester for cables.PM if u need the code.Best regards,Paul L.---------------------------------------------------------------------------------------------------------Hello everyone,Can some help me to change the code in order to use a push button to start the test and all the result to be moved from serial monitor to an LCD with I2C, the address of the LCD is (0x27) and it`s useing pin21_SCL, pin20_SDA 5V and GND. If its anyone with more experience then me and could do that, the help is welcome :)Download the Code <- here you will find the code named test28.ino and the LCD code that I used to test the LCD, and a text file with the pins used by the LCD.Thank you,Paul Lungoci

Question by LungociP 1 year ago  |  last reply 1 year ago


Sciences PI Plate

Hi every ones, I'm a young engenner in plant biotechnology. On my free time i try to create an open source plate for the Raspberry pi which has lots of functionality very usefull for science project (Plant growing, Invitro cell, hydroponic control, compotemental study...) I'm really a beginer in electronics, but i read a lot electronic book, looking schematic and see video. This plate have : -8x relay 220V 5A control by a Darlington Array -8x Analog input -4x BNC connector connect to 4 Atlas Scientific Stamp (Ph, EC, DO...) -RTC clock (to be sure of time when data are store on database) -LCD screen 16x2 to facilite the reading without computer -This project will come with backend/frontend distribution Before i order all parts and PCB, i wondering if you be able to check my schematic to validate it and maybe improve it  :P Schematic Image files (2Mo) Fritzing file FZZ I have few question too  : 1/ Can i connect all my ICs and LCD to my external power supply, i read on internet this is better than connect on the 5V from the Raspberry PI? 2/ If i connect all 5V on my external supply how many amps i have to provide (the sum of all amps require by parts)? 3/ Do you know an I2C IC can replace the 74HC4052 to make all the plate in I2C and made it usable by more than a Raspberry PI ? (if it interesting) 4/ Which width is recommand for the wire on my pcb 24 mil (or smaller), and for the 220V Relay the biggest ?? Thanks you for your help, and your website ! Regards Erwan

Topic by wanoo 5 years ago


Announcing the Roboduino - the ultimate Arduino-compatible Microcontroller

The Roboduino is finally on sale!!!http://curiousinventor.com/images/kits/roboduino/roboduino.jpgIts $40 for a kit and $55 for an assembled version More info and sales information here: http://curiousinventor.com/kits/roboduino Features / Specs:100% Compatible with Arduino software.Power buses along side pwm and analog pins easily accept standard servo and sensor connectors.Powered can be supplied from USB, barrel plug or 3-pin male header. You'll need a suitable power supply when driving multiple servos.dedicated UART 3-pin male header6 PWM outputs with neighboring unregulated power pins6 analog pins14 digital pinsReverse polarity protection for board circuitry (not for unregulated power pins)Optional I2C pull-up resistor locations

Topic by Erobots 10 years ago


Help on interfacing CAT35C104 Serial EEPROM to my arduino UNO please.? Answered

Hey, I'm still semi new to Arduino, but I can read/write to analog/digital pins and communicate via I2C and SPI with other devices and micro controllers, but those are more widely known and I have here with me a ton of 8 PIN DIP, CAT35C104 Serial EEPROM IC's.. And with all that EEPROM lying around I wanted to put it to some use. But I am still not an expert and don't know how to begin to interface it to my Arduino UNO R3.. :L Specifically it shows: CAT35C104 Serial EEPROM 4kb data storage, 512 x 8 bit registers, 256 x 16 bit Can anyone help me get this to work? I also have trouble with "opcodes" kinda confused.. right now I know the times it takes to read/write, and the clock frequency (1MHz) And the pin diagram.. Any help would be appreciated!!!!!

Question by Mudbud 6 years ago  |  last reply 6 years ago


programming help

First of all, I am new to this. But for my CEIS course project I decided to program an rc vehicle because I thought it would be COOL! Now I am knee deep into the project and I am needing guidance.  So I am going to attempt to stack raspberry pi hats. One adafruit pwm for servos and the other adafruit pwm for dc and stepper motors. The first thing I done wrong was solder the gpio headers on backwards. Since I'm not too professional with a soldering iron I ended up making the drives of no use and ordered more. Before I done that, I got my pi camera working! Still need to program the pan/tilt servos. I have battery power, wiring, almost everything as far as hardware. Just not sure if I am headed in the right direction. I tried different things with python and the i2c but now when I start up the Kernel Module fails.  Any help will be great!

Topic by SMILEY4242 1 year ago


Need help to spec a microcontroller.

​Hello! I am looking for a bit of guidance as I have limited knowledge in programming Microcontrollers...amateur experience covers a bit of Arduino and LabVIEW (mostly). My goal is to have an LCD display (Module size +- 65 x 40 mm, with SPI or I2C Comms, Monochromatic) to display small error message/codes and other information as for example temperature, speed, Test number and Timer. I do not know what would be the best Microcontroller to use that is off the shelf, that will still be in production for years to come and is "less complicated" to learn...from what I have read, perhaps the best microcontroller might be the Atmel just don't know what model (am open to other suggestions) Also there shall be 20 push buttons connected to the microcontroller. All that the microcontroller does is read the buttons as a byte and send it to another controller and receive information from that controller to know what information to display on the LCD. It shall also inform the controller of any error that it is experiencing.  I do hope that I am providing with clear and enough information so that someone could point me in the right direction.  Thank you in advance.

Topic by Art_Rob 1 year ago  |  last reply 1 year ago


How do I connect several Arduinos through RS485 with the SN75176 chip? Answered

Hello, I want to connect several Arduinos together in a star network (1 Master, several Slaves), but they're too far apart, so I can't use I2C. I researched a bit and found that I can use the serial protocol RS485 and that I can use the SN75176 or the MAX485 chips to do it. Being the MAX485 more expensive than the SN75176, I bought the latter. My problem is: now that I have the SN75176 (I have two, actually), what do I do? I have no clue whatsoever. I found some circuits for the MAX485, but I don't quite get how I should connect them to the Arduino.. Anyway, the chip I have is the SN75176... The only thing I find with Google is about DMX - for lights and stuff like that -, but I'm not interested in that. I just want several Arduinos to send data gathered from temperature and humidity sensors to another Arduino... Thank you very much. :)

Question by pedrotome 8 years ago  |  last reply 4 years ago


3 wire interface (GND, VCC, DATA)? Answered

Hi guys,   I'm trying to reverse the communications on a project I have at the moment which seems to be using a 3 wire serial interface (GND, VCC, DATA).  My goal would be to replicate the communications with an arduino or similar, however i'm not 100% sure what serial protocol it's using.   The device is using an Atmel ATMEGA168 and the pcb is covered in conformal coating, so I haven't had a whole lot of luck tracing the pins. I'm not overly aware of many one-wire communications protocols.  The datasheet says the ATMEGA supports various peripheral features, including SPI, USART, 2-wire serial (Philips I2C) (among others), however the GND, VCC, DATA configuration doesn't seem to fit with any of the supported protocols (i.e. there's no clock line and only a single data line).   The captures i'm getting seem to indicate that it's an 8-bit binary protocol.  I was going to try to decode it manually and attempt to reproduce it, however would be grateful if someone recognizes it and can point me in the right direction. Does anyone know any protocols / configurations this could be?  Example screenshot attached. Any help would be greatly appreciated!  Thanks!

Question by ikarus6 3 years ago  |  last reply 3 years ago


NodeMCU to NodeMCU communication

Dear All,I am really a newbie here playing with two NodeMCUs. I started out with basics and after a while I stepped into my actual project. The project is to display toilet status indicator. My plan is to pick up the data from PIR sensor and feed it to one NodeMCU and have another NodeMCU process the data on the other end of the room and display the status on and I2c 16 x 2 LCD. I was able to connect the PIR and LCD onto one NodeMCU and test it and things were fine. I am really looking for some help to use TCP/IP protocol to have the nodeMCUs communicate to each other.My basic code is as below:#include#include int sensor = 13;LiquidCrystal_I2C lcd(0x27, 16, 2);void setup(){ Serial.begin(115200);Wire.begin(D2, D1); pinMode(sensor, INPUT); pinMode(LED_BUILTIN, OUTPUT);lcd.begin(); }void loop (){ long state = digitalRead(13); if (state == HIGH){ Serial.println("Motion recognized"); lcd.setCursor(5, 0); lcd.print("RESTROOM IS"); lcd.setCursor(0, 1); lcd.print("OCCUPIED"); digitalWrite (LED_BUILTIN, LOW); delay(5000); lcd.clear(); } else { if (state == LOW); Serial.println("Motion Absent!"); lcd.setCursor(0, 1); lcd.print("NOW VACANT"); digitalWrite(LED_BUILTIN, HIGH); delay(5000); lcd.clear(); }}Thanks for any help you can provide or guide me to examples.

Question by BharatharajV 2 months ago


How to use Multiple mcp23017 chips with the adafruit mcp23017.h library?

I have been experimenting with I2C and the mcp23017 IO expander chip for my arduino ATMega2560 as I would rather use the IO on the arduino its self for other things I am just figuring out how to use the adafruit mcp23017.h library and cant figure out how to address multiple mcp23017 chips and how to use there pins individually this is the code from the button library that I editied. Here is the datesheet of mcp23017 I want to be able to address the individual chips and the pins I was not quite sure if in the setup that the pin modes for the IO go up sequentially from 0 past 15 if multiple chips are connected and addressed in code. For example if the first chip is addressed as 0x20 and the IO number count is from 0 - 15 if I added and addressed another chip as 0x21 will that count go from 0 - 15 to 0 - 31. ~ Edit if you could recommend or send a library that would be easier or could help please do. #include #include "Adafruit_MCP23017.h" //pin 1 and 0 are mcp pins not arduino IO pins Adafruit_MCP23017 mcp; void setup() {  mcp.begin();      // use default address 0 mcp.pinMode(0, INPUT); mcp.pinMode(1, OUTPUT); Serial.begin(9600); pinMode(13, OUTPUT);  // use the p13 LED as debugging } void loop() { // The LED will 'echo' the button digitalWrite(13, mcp.digitalRead(0)); //Writes pin 13 to the reading of pin    0 mcp.digitalWrite(1, mcp.digitalRead(0)); //Writes pin 1 to the reading of 0 if(mcp.digitalRead(1) == HIGH){ //if pin 1 == high serialprint led whent   high Serial.println("Led whent HIGH"); } }

Question by DELETED_MakiY2 1 year ago  |  last reply 1 year ago


How to make the GY-87 work probably ?

Hey, This my first question and ... action here with this new account :) My problem is I'm making a quad-copter, which needs some balance and no problem of adding some features like alt. measurement and so. I bought a GY-87 10DOF chip which combines 5 sensors :- MPU6050 Gyroscope MPU6050 Accelerometer BMP085 Barometer BMP085 Temperature sensor HMC5883L Magnometer I don't know yet how to make the quad-copter balance using the chip but I'm focusing now on making the chip work at all. After 7 hours of searching I could get a messy code using KALMAN filter to get the gyro and accel angels which worked fine eccept that the code combines the Z axis with the compass reading and I need to understand how to make every reading separate, which get us to the secong problem, the compass is stuck at 50.3 degrees, after reading i found that i must enable the I2C cuz both of the MPU and the HMC uses the same bus ways, I added a delay (100) ms to let the HMC get it's reading, i could make it work till I realized that the reading is not from 0- 360, it's between 200 and ... maybe 342 ! although making the BMP work was difficult a bit.. now my questions are :- -Understand how the gyro code works or at least add the Z axis of the the gyro not the compass -How to make the compass work probably Files:- https://drive.google.com/open?id=0BxGMyrtCX-KJVHB5S1luZ3VLeGM Libs:- https://drive.google.com/open?id=0BxGMyrtCX-KJcXZ6VlZmejRDR2c

Question by Mavrick23 2 years ago


Do you want to use Skype out more comfortable and convenient

Inside 128M USB Disk. It can be changed as the clients wish 128*64 Dot Matrix LCM, it can show multi-language and information of calls wonderfully It can show the date and time Compatible with VoIP (Voice over Internet Protocol) solution such as SKYPE It can make a PC-to-PC calls for free and PC to PSTN or MOBILE calls through Internet. Echo-cancellation for better sound quality Can set speed dials, design as mobile phone There is a DTMF dialing keyboard, can dial on the phone as normal phone Can make a call to SKYPE by using SKYPE software, or make a call to normal phone by SKYPE out Professional processor and special arithmetic for high timbre quality Use I2C port, more simply and convenient Inside LED, shows the statement of coming calls, calls, silence, dialing, on hook, name list It can save the received calls and the dialed number as many as you wish It can make a call through SKYPE calling list Several types of ring tones for incoming call alert, The display of USB Phone and SKYPE can be concurrence As a speaker to broadcast music from PC No need superfluity power supply Can adjust the volume during a call Connecting statement auto-checking No need to bear the ‘earphone and microphone’, just answer the phone when it rings One phone for VoIP, make it more convenient Can use as the earphone of Yahoo Messenger, MSN Messenger, MS NetMeeting, Talk and so on, supports dialing by USB We can exploit more functions according to the customer's inner information about the operation details So if you have any requirement of VoIP equipment, please contact us. TEL:+86-755-27918959 MSN: cobbyzhou@hotmail.com Skype: cobbyzhou Yahoo Massager: cobby_zhou E-mail: cobbyzhou@hotmail.com

Topic by cobbyzhou 12 years ago  |  last reply 12 years ago


accelerometer based mouse, what happens when tilted

I got a free dual axis low g accelerometer from freescale, the output voltage is proportional to the g forces, I also have a ton of free PICmicro chips with I2C and A/D converters. I want to make a mouse just basically for proof of concept. I was thinking about how to program it, since I want to tell the computer the "movement since last request", I would need to calculate the speed using the g force reading (9.8m/s2 = 1g)if the mouse is moving at a constant speed, the g force would be 0, and the speed would be the same as the last reading, also, gravity affects the reading if the mouse is tilted slightly, increasing the speed even if it is not moving at all, so I was thinking, if the mouse was tilted, and then balanced again, the speed would remain the same, causing annoyance to the user. this is the problem i would like to solve.Is there a space efficient way to make a accelerometer not affected by tilt? if not, is there any tricks I can use (such as detecting unusually uniform g force and automatically go into "joystick mode")? I have been thinking about using a thumb button to zero the speed (while held down, the mouse can also do "super precise mode" which means one pixel per half second no mater how fast), is the thumb button the way to go? how about sensor to see if there is contact with a surface? or four IR rangers to detect tilt while above a surface?side note: does anybody have a datasheet for ata1060xa? its a optical mouse sensor with built in 27mhz RF transmitter made by @lab, and they don't share datasheets.oh and head on over to cypress for free wireless usb modules (2.4ghz i think, multiple channels) if you are interested in cheap RF, i have two with 50 meter rangeinfo on mouses and keyboard serial interface found herehttp://www.computer-engineering.org/ps2protocol/

Topic by frank26080115 12 years ago  |  last reply 12 years ago


Timer,Temprature & Humidity Based Relay Switching with Arduino Mega.? Answered

I am making a Climate Controler for my Green House. Please help me about Arduino code for Four Relay operation. relay1 will be high when Temp will rise higher then Temprature value defined and will low when reach under defined value. relay2 will be high when Humidity will rise higher then Humidity value defined and will low when reach under defined value  relay3 will be high for 10 Minutes in every 120 Minutes. relay4 will be high for 10 Minutes in every 120 Minutes.  I am Using DHT11 sensor with Mega2560 Board. Currently using this code. Its working for Temp & Humidty based Relay operation only. Need to add two relay with Timer based operation. System needs to check Humidity and Temprature value in every 10 minutes. Please Help.  I am very new for Arduino and making this for my personal use. #include #include #include /*-----( Declare objects )-----*/ // set the LCD address to 0x27 for a 20 chars 4 line display // Set the pins on the I2C chip used for LCD connections: //                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol LiquidCrystal lcd(20, 19, 18, 17, 16, 15); // Set the LCD I2C address dht11 DHT11; /*-----( Declare Constants, Pin Numbers )-----*/ #define DHT11PIN 22 #define RELAY1  6                        #define RELAY2  7                        #define RELAY3  4                        #define RELAY4  5 #define TempTarget 30 #define HUMTarget 50 void setup()   /*----( SETUP: RUNS ONCE )----*/ {   Serial.begin(9600); //(Remove all 'Serial' commands if not needed)   lcd.begin(20,2);         // initialize the lcd for 20 chars 4 lines, turn on backlight     // Print a message to the LCD.   //lcd.setCursor(0, 1);   lcd.print("SHOURYA's GARDEN");   // Initialise the Arduino data pins for OUTPUT   pinMode(RELAY1, OUTPUT);         pinMode(RELAY2, OUTPUT);   pinMode(RELAY3, OUTPUT);   pinMode(RELAY4, OUTPUT);   }/*--(end setup )---*/ void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/ {   int chk = DHT11.read(DHT11PIN);   Serial.print   ("GARDEN DATA SENSING ");   switch (chk)   {     case 0: Serial.println(" OK"); break;     case -1: Serial.println("Checksum error"); break;     case -2: Serial.println("Time out error"); break;     default: Serial.println("Unknown error"); break;   }   lcd.setCursor(0, 1);   lcd.print("TempC=");   lcd.print((float)DHT11.temperature, 0);   Serial.print("Temperature (oC): ");   Serial.println((float)DHT11.temperature, 2);   //lcd.print(" F=");   //lcd.print(Fahrenheit(DHT11.temperature), 0);   //Serial.print("Temperature (oF): ");   //Serial.println(Fahrenheit(DHT11.temperature), 2);     lcd.print(" Hum=");   lcd.print((float)DHT11.humidity, 0);   lcd.print("%");   Serial.print("Humid(%): ");   Serial.println((float)DHT11.humidity, 2);    //Serial.print("Temperature (K): ");   //Serial.println(Kelvin(DHT11.temperature), 2);   //Serial.print("Dew Point (oC): ");   //Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));   //Serial.print("Dew PointFast (oC): ");   //Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));        if (DHT11.temperature > TempTarget)       { Serial.println("Turning on Exaust Fan"); //lcd.print("Turning on Exaust Fan"); digitalWrite (RELAY1, HIGH); delay(1000);     }      if (DHT11.temperature < TempTarget)     { Serial.println("Turning Off Exaust Fan"); //lcd.print("Turning off Exaust Fan"); digitalWrite (RELAY1, LOW); delay(1000);     }       if (DHT11.humidity < HUMTarget)     { Serial.println("Turning on HUMIDIFIER"); //lcd.print("Turning on HUMIDIFIER"); digitalWrite (RELAY2, HIGH); delay(1000);     }      if (DHT11.humidity > HUMTarget)     { Serial.println("Turning Off HUMIDIFIER"); //lcd.print("Turning off HUMIDIFIER"); digitalWrite (RELAY2, LOW); delay(1000);     }       digitalWrite(RELAY3,HIGH);           // Turns ON Relays 3    digitalWrite(RELAY4,HIGH);           // Turns ON Relays 4    delay(10*1000);     digitalWrite(RELAY3,LOW);          // Turns Relay Off    digitalWrite(RELAY4,LOW);          // Turns Relay Off   }/* --(end main loop )-- */ /*-----( Declare User-written Functions )-----*/ // //Celsius to Fahrenheit conversion double Fahrenheit(double celsius) {         return 1.8 * celsius + 32; } //Celsius to Kelvin conversion double Kelvin(double celsius) {         return celsius + 273.15; } // dewPoint function NOAA // reference: http://wahiduddin.net/calc/density_algorithms.htm double dewPoint(double celsius, double humidity) {         double A0= 373.15/(273.15 + celsius);         double SUM = -7.90298 * (A0-1);         SUM += 5.02808 * log10(A0);         SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;         SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;         SUM += log10(1013.246);         double VP = pow(10, SUM-3) * humidity;         double T = log(VP/0.61078);   // temp var         return (241.88 * T) / (17.558-T); } // delta max = 0.6544 wrt dewPoint() // 5x faster than dewPoint() // reference: http://en.wikipedia.org/wiki/Dew_point double dewPointFast(double celsius, double humidity) {         double a = 17.271;         double b = 237.7;         double temp = (a * celsius) / (b + celsius) + log(humidity/100);         double Td = (b * temp) / (a - temp);         return Td; } /* ( THE END ) */

Question by achauhan13 4 years ago  |  last reply 3 years ago


why does the lcd shows the old value after I make the power off ?

Hello, my project is a Real Time Digital Clock I'm using LCD 16x 2 with DS1307 connected with pic18f4550 when i burn the code to the circuit it shows the time correctly but when i make the power off then make it ON it shows the previous code which is not correctly ! How can i fix this ? shall i use battery for the DS1307 ? what do you suggest from me ? this is the code written in mikroc  : #ifndef DS1307 #define DS1307 0xD0 #endif // Software I2C connections sbit Soft_I2C_Scl at RB1_bit; sbit Soft_I2C_Sda at RB0_bit; sbit Soft_I2C_Scl_Direction at TRISB1_bit; sbit Soft_I2C_Sda_Direction at TRISB0_bit; // End Software I2C connections sbit LCD_RS at RB3_bit; sbit LCD_RW at RD0_bit; sbit LCD_EN at RB2_bit; sbit LCD_D4 at RD1_bit; sbit LCD_D5 at RD2_bit; sbit LCD_D6 at RD3_bit; sbit LCD_D7 at RD4_bit; sbit LCD_RS_Direction at TRISB3_bit; sbit LCD_RW_Direction at TRISD0_bit; sbit LCD_EN_Direction at TRISB2_bit; sbit LCD_D4_Direction at TRISD1_bit; sbit LCD_D5_Direction at TRISD2_bit; sbit LCD_D6_Direction at TRISD3_bit; sbit LCD_D7_Direction at TRISD4_bit; char i; unsigned char sec, min1, hr, week_day, day, mn, year; char *txt, tnum[4]; // for some other testing char txtSec[10]; char txtMin[10]; char txtHour[10]; char txtWeekDay[10]; char txtDay[10]; char txtMn[10]; char txtYear[5]; char txtDisplay[39]; // for some testing int intSec, intMin, intHour, intWeekDay, intMn, intDay, intYear; void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {         Soft_I2C_Start();         Soft_I2C_Write(DS1307);         Soft_I2C_Write(0x00);         Soft_I2C_Start();         Soft_I2C_Write(0xD1);     //MAKE SURE D1 IS ADDRSS OF PIC18F4550         *sec =Soft_I2C_Read(1);         *min =Soft_I2C_Read(1);         *hr =Soft_I2C_Read(1);         *week_day =Soft_I2C_Read(1);         *day =Soft_I2C_Read(1);         *mn =Soft_I2C_Read(1);         *year =Soft_I2C_Read(0);         Soft_I2C_Stop(); } /* void Transform_Time(char  *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {         *sec  =  ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);         *min  =  ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);         *hr   =  ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);         *week_day =(*week_day & 0x07);         *day  =  ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);         *mn   =  ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);         *year =  ((*year & 0xF0)>>4)*10+(*year & 0x0F); }  **/ //-------------------- Formats date and time void Transform_Time() {   *sec  =  ((*sec & 0xF0) >> 4)*10 + (*sec & 0x0F);  // Transform seconds   *min  =  ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);  // Transform months *hr    =  ((*hr & 0xF0)  >> 4)*10  + (*hr & 0x0F);    // Transform hours   *year    =   (*year & 0xC0) >> 6;                             // Transform year   *day     =  ((*day  & 0x30) >> 4)*10    + (*day  & 0x0F);       // Transform day *mn   =  ((*mn & 0x10)  >> 4)*10 + (*mn & 0x0F);     // Transform month } void Write_Time() {         Soft_I2C_Start();          // issue start signal         Soft_I2C_Write(DS1307);       // address DS1307         Soft_I2C_Write(0);            // start from word at address (REG0)         Soft_I2C_Write(0x40);         // write 17 to hours word (24-hours mode)(REG2) (sec)*         Soft_I2C_Write(0x23);         // write 2 - Monday (REG3)   ,( min ) *         Soft_I2C_Write(0x14);         // write 4 to date word (REG4)  (hr) *         Soft_I2C_Write(0x03);         // write 5 (May) to month word (REG5) (day)*         Soft_I2C_Write(0x14);         // write 01 to year word (REG6) (year)*         Soft_I2C_Write(0x05);         Soft_I2C_Write(0x13);         Soft_I2C_Stop();           // issue stop signal         Soft_I2C_Start();          // issue start signal         Soft_I2C_Write(DS1307);       // address DS1307         Soft_I2C_Write(0);            // start from word at address 0         Soft_I2C_Write(0);            // write 0 to REG0 (enable counting + 0 sec)         Soft_I2C_Stop();          // issue stop signal } void Transform_Time(char  *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {         *sec  =  ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);         *min  =  ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);         *hr   =  ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);         *week_day =(*week_day & 0x07);         *day  =  ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);         *mn   =  ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);         *year =  ((*year & 0xF0)>>4)*10+(*year & 0x0F); } /* void Display_Time() {         switch(week_day)         {                 case 1: txt="Sun"; break;                 case 2: txt="Mon"; break;                 case 3: txt="Tue"; break;                 case 4: txt="Wed"; break;                 case 5: txt="Thu"; break;                 case 6: txt="Fri"; break;                 case 7: txt="Sat"; break;         }   **/         Lcd_Chr(1, 6, (day / 10)   + 48);    // Print tens digit of day variable    Lcd_Chr(1, 7, (*day % 10)   + 48);    // Print oness digit of day variable    Lcd_Chr(1, 9, (*mn / 10) + 48);    Lcd_Chr(1,10, (month % 10) + 48);    Lcd_Chr(1,15,  year        + 48);    // Print year variable  (start from year 2010)    Lcd_Chr(2, 6, (hours / 10)   + 48);    Lcd_Chr(2, 7, (hours % 10)   + 48);    Lcd_Chr(2, 9, (minutes / 10) + 48);    Lcd_Chr(2,10, (minutes % 10) + 48);    Lcd_Chr(2,12, (seconds / 10) + 48);    Lcd_Chr(2,13, (seconds % 10) + 48); }         Lcd_Init();         Lcd_Cmd(_LCD_CLEAR);               // Clear display         Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off         Lcd_Out(1,1,txt);         Lcd_Chr(1, 6, (day / 10)   + 48);    // Print tens digit of day variable         Lcd_Chr(1, 7, (day % 10)   + 48);    // Print oness digit of day variable         Lcd_Chr(1,8,'.');         Lcd_Chr(1, 9, (mn / 10) + 48);         Lcd_Chr(1,10, (mn % 10) + 48);         Lcd_Chr(1,11,'.');         Lcd_Chr(1,12,  (year / 10)  + 48);          // Print year vaiable + 8 (start from year 2008)         Lcd_Chr(1,13,  (year % 10)  + 48);         txt = "Time";         Lcd_Out(2,1,txt);         Lcd_Chr(2, 6, (hr / 10)   + 48);         Lcd_Chr(2, 7, (hr % 10)   + 48);         Lcd_Chr(2,8,':');         Lcd_Chr(2, 9, (min / 10) + 48);         Lcd_Chr(2,10, (min % 10) + 48);         Lcd_Chr(2,11,':');         Lcd_Chr(2,12, (sec / 10) + 48);         Lcd_Chr(2,13, (sec % 10) + 48);         Lcd_Cmd(_LCD_CURSOR_OFF); } void Init_Main_Simple() {         ADCON1 = 0x0F; // page 268, disable analaog        // CMCON = 0x07;        // INTCON2 = 0x80; // disable pull up in port b         // clears internal latches         LATB = 0x03; // enable internal pull ups         LATA = 0x00;         LATC = 0x00;         LATD = 0x00;         LATE = 0x00;         // Make all outputs         TRISA = 0x00;         TRISB = 0x03;         TRISC = 0x00;         TRISD = 0x00;         TRISE = 0x00;         Lcd_Init();                // Initialize LCD         Lcd_Cmd(_LCD_CLEAR);       // Clear LCD display         Lcd_Cmd(_LCD_CURSOR_OFF);  // Turn cursor off         Soft_I2C_Init();                        // initialize I2C         Lcd_Out(1,1,"Time & Date"); } void main() {            Delay_ms(500);        Init_Main_Simple();        //Write_Time();         //Delay_ms(100);         while (1) {                 Read_Time(&sec;,&min1;,&hr;,&week;_day,&day;,&mn;,&year;);      // read time from RTC(DS1307)                 Transform_Time(&sec;,&min1;,&hr;,&week;_day,&day;,&mn;,&year;); // format date and time                 Display_Time(sec, min1, hr, week_day, day, mn, year);                 Delay_ms(1000);         } } Thanks

Question by dndanah1 6 years ago  |  last reply 6 years ago