Reading a 16x2 LCD screen

Dear Techfreaks, I have a rather technical question for you guys. I have a big, company-suited coffee machine which I'd like to mod, to be internet connected. My idea is to read the LCD screen of the machine, by intercepting the wires, and interpreting the signals with a microcontroller. I'd need to read the data, and convert it into ASCII, so I can drop them on a website, and in fact have a (sort of live) view of the LCD.  The used LCD is a standard 16x2, 16-pin LCD. Does anyone have any experience with doing this? Or any tips? I couldn't find a project online which wanted to do the same thing as I did. Thanks in Advance, Willem. 

Topic by WillemB14 3 years ago  |  last reply 3 years ago


Powering a 16x2 LCD Screen? Answered

Hey all I am relatively new to the Arduino platform and learning as I go. I have a 16x2 LCD screen that I am trying to learn how to use. I hooked my positive lead to pin 2 and the Ground to pin1 and nothing lit up. I then hooked a potentiometer up to pin 3 to try and adjust the contrast still nothing lit up. Does this mean my LCD screen is broken? I haven't sent any code to it so I am not expecting it to "say" anything, but i thought when the power was on it would at least light up? Please let me know if i need todo anything else to make it light up or if I need to buy a new LCD. Thanks!

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


How to interface a 16x2 lcd with fpga

I have to interface a 16x2 lcd with spartan 3 trainer board using xilinx .. Im looking for pointers in the right direction. Any ideas ?

Topic by Hussam 7 years ago  |  last reply 7 years ago


Help with an arduino 16x2 LCD sketch?

Hey all. Im new to arduino and have bought a 16x2 lcd to learn more about the ide. I was able to write the simple text. Then i also scrolled it. But now i want that the upper line should be static and the lower line should move. How can i achieve this effect. Also when scrolling a piece of sentence (lets say right to left), when the sentence goes completely toward left, it doesn't appear from the right until the whole sentence has not disappeared. This leaves a lot of space in between. I want that the moment text touches the left, it starts coming back from the right ( like what was there in the old snakes game that came with all primitive phones).  Plz reply fast......Thanks a lot! :)

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


Hi, I have a problem with a 16x2 lcd... Answered

So I connect this display to my arduino uno and I upload the code from the arduino website. I also do the same wiring... But the lcd displays only a row of black boxes. I tried many other wiring options and connections from the Internet but none of them works. I have always the same resut. wating your answers Thank you in advance

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


Guide for display 2nd line 16x2 LCD,Please Answered

Dear All. I have seen this site :   http://iamsuhasm.wordpress.com/tutsproj/using-lcds/ and following  from the author guide:  (Start) set D3 D2D1 D0 =0 >set EN=1and return 0> set D3...D0 =0 and continue..(please see  the instruction on this site ) I have successfully displayed what I want on the lcd 1st row but not able to display anything on the 2nd line… ( I know very little in the word programmer computer) Please help.. let me know the instruction to take the cursor to the 2nd line. Thank you in advance  for your time.                                       Best regards

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


Has anyone used OrientDisplay's 16x2 lcd board with Arduino?

I'm trying to hook up a LCD display to an Arduino Duemilanove and need help. It is a 16x2 SPI bus device from Orient Display. Part number is AMC1602AR-B-B6WTDW-SPI   Here is the information  from the mfg website on this product.  http://orientdisplay.com/products/AMC1602ASPI.pdf I'm a relative newbie and haven't done anything with the SPI bus. It is confusing for me because of all the different names given to the 4 pins of the SPI bus! HELP please!

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


how would i direct drive a 16x2 LCD with only an arduino and a PS/2 keyboard? Answered

I would  like to direct drive a lcd using an arduino and a PS/2 keyboard WITHOUT A PC. i just want to connect the  KEYBOARD to the arduino and type in the lcd. i would like help finding the code for this or help making the code.

Question by devicemodder 8 years ago  |  last reply 7 years ago


LM35 thermometer? Answered

I want to make a theromoter with pic16f88 and LM35 sensor and show the results on a 16x2 lcd plzzz  help me out

Question by robot1398 7 years ago  |  last reply 7 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 23 days ago


How do I wire a LTC3780 to my arduino and display?

I'm re-purposing an old ATX psu into a variable bench psu. The current project has LM2956's however they're faulty, I can only see 11.78V max instead of 29+V. The other down side to these modules is the lack of current control. The project also has an arduino Mega handling acs712 hall current effect sensors and Voltage dividers for my 3.3v 5v 12v terminals and two LDC dispays 16x2 and 16x4. So I was wondering assuming I keep the basic design of the psu can i replace the LM2956s for a single LTC3780, How can I wire the LTC3780 to the arduino and allow me to see the current change.  Thanx in advance.

Question by icey.hood 3 years ago  |  last reply 2 years ago


how to make a current meter with microcontrollel PIC 16f877?

I want to make a current meter with microcontroller and LCD 16x2 as display. what components do i need? and what is CT?

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


how to make current meter with PIC 16f877?

please help, if anyone knows. tell me what components do i need to make current sensor? and the process to be displayed on LCD 16x2

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


My HC-05 module is not converting AT command mode?

My HC-05 module is not converting in AT command mode and I am making a project Bluetooth controlled car using Arduino 16x2 lcd and HC-05 Bluetooth module and a Bluetooth controller android app  but it is still not working in my project any help?

Question by Aroojk 1 year 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


marble disorder v2: a 45 degree paradigm shift

I've upgraded my Marble Disorder instructable to v2 (see last step) and it's now way cooler than before (with a new video too). Not sure where I should announce such a thing, and I hope it's OK to do it here. Cheers, @TheRealDod

Topic by thedod 8 years ago  |  last reply 8 years ago


Which microcontroller to choose?

Hi all, I need to use a microcontroller for my project and am thinking of getting the arduino UNO R3 development board which composes of the ATmega328 microcontroller. I have to connect a small motor, a 16x2 LCD display and a miniature heating element to the arduino. I would like to know if the UNO R3 is suitable for my project. PS: I am very new and noob regarding microcontrollers

Topic by kurtselva 6 years ago  |  last reply 6 years ago


Arduino Morse Code decoder?

I want to make an arduino morse code decoder, which will print the result on a 16x2 LCD. The input will be 3 button, 2 will be the "_" and "." respectively, the 3rd one will be the "space" button, when press will decode the code which was input. If input was wrong then it will display a "?" mark. And it should be able to decode many character at once. Anyone have some idea or code about this? I'm just getting started with microcontroller for about 1 months so I have a bit of knowledge about how they should work, but this prove to be quite challenging for me

Question by Mad Fox 4 years ago  |  last reply 4 years ago


Arduino custom shield isn't working right...

I've been trying to figure out whats wrong on the shield i built for my intervalometer project but somehow nothing is working except bottom row of the screen (standard 16x2) is all lit up. I've checked my wiring, shoddy as it looks, several times over but nothing seems amiss. WTF is wrong? Then tonight it occurred to me, perhaps its the Vin pin that I neglected to put in since I wasn't going to need it for this project is the cause. Am I close to what might be wrong?

Question by The Ideanator 7 years ago  |  last reply 7 years ago


LCD for beginners? Answered

Hey guys I want to get started using simlpe 16x2 LCDs in my Arduino projects, but I I need one for beginners. Nothing too fancy. This is the one I'm looking at: https://www.sparkfun.com/products/709.   Also, if anyone knows where I can get one that has the three outputs( +5v, GND, and data) and/or has a link to a website, that would be extremely helpful. Thanks in advance!

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


Notifications from Android to Arduino via Bluetooth

I would like my phone to relay my notifications from the notification tray to an arduino. I had done alot of snooping around, and I have not found anything regarding doing that. Closest thing I had come to was sending notifications from the arduino itself, to the phone. But I want it the other way around. The idea is that it would display it to one of those 16x2 LCD displays, scrolling through whatever the notification says. I have yet to get the LCD, but in the meantime, I'd like to see about getting it to come through to the serial monitor. Does anyone know how to get android to do something like that?

Topic by Dashing Rainbow Dash 2 years ago  |  last reply 2 years ago


My First Project (Electronic Questions)

Good morning everyone. I'm new but very optimistic on the creation and programming in PIC and I would love Buddy aid for my project. Project Idea: Store 60 responses at most 1 character (núemro or letter), to questions such as: 1 = 2 = 3 = 60 = .... At the end of the data / informed responses would be sent to the PC via USB cable or WIFI for later imported by the PC system. My questions prior to starting the project would be as follows: I'm thinking of using PIC16F877A microchip and NOKIA5110 screen. A) Any other microship less expensive cases do this activity? B) The screen initially want to use this model because it allows me to print graphs on startup and letters larger than 16x2 screens. The following outline of the design for greater understanding.

Topic by clicsis 3 years ago  |  last reply 3 years ago


Arduino Code Modification Help (Change of Display Type Used)

This is my first post, so I hope I'm doing this correctly. For reference, I'm new to Arduino, and with no experience with code. I want to try and do a battery tester with an Uno, as seen here (http://denishennessy.com/2012/04/08/measuring-battery-capacity-with-an-arduino/). I'm trying to follow the instructions given, and use the code (https://github.com/dhennessy/BatteryCapacityTester/blob/master/BatteryTester/BatteryTester.ino) that the author has provided. However, due to lack of availability of parts, I don't have a temperature sensor, and instead of the 16x2 LCD screen, I have an Adafruit 1.8' TFT shield. So my query is, how can I modify the code such that it works on this type of display? Again, the code is from (https://github.com/dhennessy/BatteryCapacityTester/blob/master/BatteryTester/BatteryTester.ino), and I have not directly copied it in the post so that it is easier to read. Any help on this would be greatly appreciated.

Topic by f-nine 5 years ago  |  last reply 5 years ago


Arduino Game Coding - FSR (Pressure Sensor) Based Shooting Game

I'm making a shooting style arcade game in which you shoot a projectile at four different force sensitive resistors trying to rack up as many points as possible before the timer runs out. When a ball hits one of the fsr I want to have the arduino keep score and show it on a 16x2 lcd. Each one of the fsr have a different point value.              Ex:  A ball hits fsr _1 giving the player 5pts, another hits fsr_3 giving the player another 15pts. The 60 second timer then runs out and  the game shows you your score on the lcd... 20pts. I've been trying to wrap my head around how to code something like this but I am just making myself more confused. Any help would be appreciated! Thanks!

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


Is it possible to connect old copimachine LCD to arduino?

Hi everyone! Im new here in the forums and i think its a great community. I have always been in love with robots and electronics ever since i was little. And now im starting to play with the world of arduino! I recently scrapped an old copimachine for parts. Mostly steppers, shafts and other usefull stuff. In the machine there was an color LCD touch display. Its about $100 new on Ebay. But before i sell it off i would like to know if i could hook it up on the Arduino and use it as an display to show the time ect. It has an outer touchscreen sensor also. Can I get it to work or do  i just need to sell it an buy an 16X2 green and black lcd instead?  The screen model is LSUGC2131A (google it) or see this http://www.aliexpress.com/store/product/LSUGC2022A-LSUGC2131A/811238_884227702.html Also if anyone can find the Datasheet for this one it would be a great help. Any help is appreciated :) - Joey 

Topic by rasmussen105 3 years ago  |  last reply 3 years ago


Gap measurement using a sensor

I want to measure a very tiny gap of about 20-30 microns(0.02-0.03 mm) using a sensor with the help of arduino and then display it using a 16x2 Digital LCD Display. Can someone help me out with the sensor that I will need for this purpose with exact name and its working.The gap that I want to measure is the gap between the the joints of a healing fractured bone.(the joint where the tissues develop to join the broken parts together.)Since this is a leg bone any person walking with such a fractured bone will put pressure on the bone and the gap present in the bone will reduce. So that is what I want to measure using a sensor and arduino. Since this gap will be too small (20-30 microns) I am unable to find a suitable sensor for the same.PS: Main issue I am facing is the measurement of gap using a sensor and arduino since I can find a suitable sensor for the same.Please find the attachments of the bone and the gap I want to measure.Also the thing I am doing is a close case of greenstick fracture. refer to the attachment of greenstick fracture.

Topic by ChinmayV2 11 months ago


Is it ok to post it?

Hey Instructables! So a couple of weeks ago I finished a year long project, automating my room. The project is completly modular so if any piece burns out or fails you can quickly switch it, the project includes automatic lighting controlled via a PIR sensor, an LM35 controlled fan, a miniature green house controlled by another LM35 and it displays the info about humidity and temp, through a 16x2 lcd and DHT11, a combination lock for my door via a keypad, a infrared control that can turn on or of my desk lamp, alarm clock, room lights, solder station and has the function to turn the whole system on or off, it also includes a modified Sony alarm clock, that has a TDA2040 amplifier with aux in and its connected to some speakers around my room. I have all the eagle files and ready to print pdf´s. Everything is controlled by 2 DIY arduinos. I made most of the modules for the sensor array but a couple of the controll modules were made using already existing files on fritzing, and the DIY-Duino https://www.instructables.com/id/DIY-Arduino-or-The-DIY-Duino/ Should I redesign this modules and controller board before uploading, or will crediting the authors of this parts will do?

Topic by GG_Beta 5 years ago  |  last reply 5 years ago


Why doesn't my Arduino 'secret thermometer' print to LCD? Answered

[Solved] I've had my Arduino a few days now and have found this code: code.google.com/p/tinkerit/wiki/SecretThermometer. I have tried modifying it with a few basic LCD commands, which I have had working with a 16x2 LCD. I want it to print the temperature from "readTemp()", divide by 10000 (to get it in degrees C) and print to the LCD (with the "C" character after it). This is what I have so far: #include LiquidCrystal lcd(7, 6, 5, 4, 3, 2); long readTemp() { long result; ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3); delay(2); ADCSRA |= _BV(ADSC); while (bit_is_set(ADCSRA,ADSC)); result = ADCL; result |= ADCH<<8; result = (result - 125) * 1075; return result; } int temp = (readTemp()/10000, DEC); void setup(){ lcd.clear(); lcd.begin(16, 2); lcd.print("Thermuino"); delay(2000); lcd.clear(); } void loop(){ lcd.setCursor(3, 0); lcd.print("C"); lcd.setCursor(0, 0); lcd.print(temp); // is this where the problem is? delay(1000); } But it does not work, I have checked all I/O lines,  different code etc. and they all work fine. So It must be a mistake in my programming. All I get is row 0 of the LCD full black all characters along it. I hope I have provided enough information for you to help :-D [EDIT] After removing the "int temp = (readTemp()/10000, DEC);" section and changing "lcd.print(temp);" to "lcd.print(readTemp()/10000);"  it now works! :-D It prints a correct temperature to the LCD and refreshes it.

Question by DELETED_zoltzerino 9 years ago  |  last reply 9 years 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


Topper

This is the beginning of a project I've been wanting to do for a while now. I'm just learning microcontrollers and electronics, so anyone if there is anyone out there who notices me doing something stupid, please let me know. I have a 12-gallon Nano Cube reef aquarium. I want to automate as much of the maintenance as I can. I'm going to start with adding top-off water. This is Topper v1.0 and like any vX.0 you can count on it having problems.Now I know some of you are probably wondering why I don't write this up as an instructable. Well, that is on my list, but it has a ways to go before its ready. I mean, take a look at it! Isn't that the ugliest thing you've ever seen?When the whole thing is finished and prettied up I'll make an instructable out of it. Eventually I'll want to switch to an AVR microcontroller because of the cost. But the Parallax Basic Stamp is just so much easier for quick and dirty programming.Here is the initial controller program.'---------------------------------------------------------------' FloatSwitchTest.bs2' First attempt to control the top off pump with the Stamp' {$STAMP BS2}' {$PBASIC 2.5}DO IF (IN15 = 0) THEN 'Reads float switch HIGH 14 'Turns on pump HIGH 6 'Turns on LED ELSE LOW 14 'Turns off pump LOW 6 'Turns off LED ENDIF PAUSE 1000 'One second pauseLOOP'----------------------------------------------------------------This is just to get things started, but already its nice not having to top it off every day and even at that, the swing in salinity was more than I was happy with.The pump is a Tom Aquarium Products AW-20. At 3.5 gph and a 30" head, with nearly that from top off water to tank and a "one way valve" I wasn't sure how often it would come on or how long it would run at a time. So far, its been running 3-4 times a day for 35 - 40 seconds at a shot. I've started adding Kent Marine Superbuffer-dKH to the top off watch. I want to keep it at about 10 dKH.Anyone looking closely at the photo will notice an IC not listed on the circuit diagram. Its a DS1302 real-time clock and microcontroller isn't currently using it. Next up is connecting that and a 16x2 LCD display to show the time and track how long the pump runs.All comments are welcome, from "I'm curious why you..." to "ARE YOU INSANE?!?!".

Topic by GlobalVillageIdiot 11 years ago  |  last reply 11 years ago


How to get data from a load sensor through bluetooth module on an Android App/Arduino?

I am creating a mobile android application which gets data from a load sensor connected to HC-06 Bluetooth module and sends the data to a mobile application. The mobile app has two activities one for listing the bluetooth devices available and the other is the main activity to get data from the load sensor. I have managed to connect/pair with the Bluetooth module but I am unable to get data from it. The main activity consists of a button 'btnScan' that will get the data, and a text field to display the data. Can someone please help?  Here is the MainActivity File package com.uniproj.senseplate; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;   public class MainActivity extends Activity {       Button btnscan;   TextView txtArduino, txtString, txtStringLength, calorie;   Handler bluetoothIn;   final int handlerState = 0;             //used to identify handler message   private BluetoothAdapter btAdapter = null;   private BluetoothSocket btSocket; //= null;   private StringBuilder recDataString = new StringBuilder();      private ConnectedThread mConnectedThread;       // SPP UUID service - this should work for most devices   private static final UUID BTMODULEUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");     // String for MAC address   private static String address; @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       //Link the buttons and textViews to respective views                    btnscan = (Button) findViewById(R.id.scanBtn);                 txtString = (TextView) findViewById(R.id.txtString);     txtStringLength = (TextView) findViewById(R.id.testView1);       calorie = (TextView) findViewById(R.id.sensorView1);     bluetoothIn = new Handler() {         public void handleMessage(android.os.Message msg) {             if (msg.what == handlerState) {          //if message is what we want              String readMessage = (String) msg.obj;                                                                // msg.arg1 = bytes from connect thread                 recDataString.append(readMessage);              //keep appending to string until ~                 int endOfLineIndex = recDataString.indexOf("~");                    // determine the end-of-line                 if (endOfLineIndex > 0) {                                           // make sure there data before ~                     String dataInPrint = recDataString.substring(0, endOfLineIndex);    // extract string                     txtString.setText("Data Received = " + dataInPrint);                                 int dataLength = dataInPrint.length();       //get length of data received                     txtStringLength.setText("String Length = " + String.valueOf(dataLength));                                         if (recDataString.charAt(0) == '#')        //if it starts with # we know it is what we are looking for                     {                      //get sensor value from string between indices 1-5                      String weight = recDataString.substring(1, 5);                      //update the textviews with sensor values                      calorie.setText(weight + "kg");                            }                     recDataString.delete(0, recDataString.length());      //clear all string data                    // strIncom =" ";                     dataInPrint = " ";                 }                        }         }     };           btAdapter = BluetoothAdapter.getDefaultAdapter();       // get Bluetooth adapter     checkBTState();        // Set up onClick listeners for button to scan for data     btnscan.setOnClickListener(new OnClickListener() {       public void onClick(View v) {         mConnectedThread.read("1");       }     }); }   private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {             return  device.createRfcommSocketToServiceRecord(BTMODULEUUID);       //creates secure outgoing connecetion with BT device using UUID   }       @Override   public void onResume() {     super.onResume();         //Get MAC address from DeviceListActivity via intent     Intent intent = getIntent();         //Get the MAC address from the DeviceListActivty via EXTRA     address = intent.getStringExtra(DeviceListActivity.EXTRA_DEVICE_ADDRESS);     //create device and set the MAC address     BluetoothDevice device = btAdapter.getRemoteDevice(address);          try {         btSocket = createBluetoothSocket(device);     } catch (IOException e) {      Toast.makeText(getBaseContext(), "Socket creation failed", Toast.LENGTH_LONG).show();     }      // Establish the Bluetooth socket connection.     try     {       btSocket.connect();     } catch (IOException e) {       try       {         btSocket.close();       } catch (IOException e2)       {      //insert code to deal with this       }     }     mConnectedThread = new ConnectedThread(btSocket);     mConnectedThread.start();         //I send a character when resuming.beginning transmission to check device is connected     //If it is not an exception will be thrown in the write method and finish() will be called     //mConnectedThread.write("x");   }     @Override   public void onPause()   {     super.onPause();     try     {     //Don't leave Bluetooth sockets open when leaving activity       btSocket.close();     } catch (IOException e2) {      //insert code to deal with this     }   } //Checks that the Android device Bluetooth is available and prompts to be turned on if off   private void checkBTState() {     if(btAdapter==null) {      Toast.makeText(getBaseContext(), "Device does not support bluetooth", Toast.LENGTH_LONG).show();     } else {       if (btAdapter.isEnabled()) {       } else {         Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);         startActivityForResult(enableBtIntent, 1);       }     }   }     //create new class for connect thread   private class ConnectedThread extends Thread {         private final InputStream mmInStream;         @SuppressWarnings("unused")   private final OutputStream mmOutStream;               //creation of the connect thread         public ConnectedThread(BluetoothSocket socket) {          btSocket = socket;             InputStream tmpIn = null;             OutputStream tmpOut = null;             try {              //Create I/O streams for connection                 tmpIn = socket.getInputStream();                 tmpOut = socket.getOutputStream();             } catch (IOException e) { }                   mmInStream = tmpIn;             mmOutStream = tmpOut;         }                 public void run() {             byte[] buffer = new byte[1024];              int bytes;             // Keep looping to listen for received messages             while (true) {                 try {                     bytes = mmInStream.read(buffer);                     bluetoothIn.obtainMessage(handlerState, bytes, -1, buffer).sendToTarget();                 } catch (IOException e) {                     break;                 }             }         }                 //write method         public void read(String input) {             byte[] bytes = input.getBytes();//converts entered String into bytes             try {                 mmInStream.read(bytes);//write bytes over BT connection via outstream             } catch (IOException e) {               //if you cannot write, close the application              Toast.makeText(getBaseContext(), "Connection Failed", Toast.LENGTH_LONG).show();              finish();                            }          }      } } Here is the Arduino file #include int led = 13; int button = 12; LiquidCrystal lcd(9, 8, 4, 5, 6, 7); // Pins used for inputs and outputs******************************************************** float sensorValue1; float containerValue; char inbyte = 0; int flag; const int numReadings = 50; int readings[numReadings]; int index = 0; int total = 0; int average = 0; //******************************************************************************************* void setup() {     pinMode(led, OUTPUT);   digitalWrite(led, HIGH);   Serial.begin(9600);     for (int thisReading = 0; thisReading < numReadings; thisReading++)   {       readings[thisReading] = 0;   }     lcd.begin(16, 2); //change to 16, 2 for smaller 16x2 screens   lcd.clear();   lcd.print("hello, world!");   delay (1000);   lcd.clear();   delay (500); } void loop() {   digitalWrite(led, HIGH);   readSensor2();    //DONE       printLCD();       //DONE   return; sendAndroidValues();   //when serial values have been received this will be true   if (Serial.available() > 0)   {     inbyte = Serial.read();     if (inbyte == '0')     {       //LED off       digitalWrite(led, LOW);     }     if (inbyte == '1')     {       //LED on       digitalWrite(led, HIGH);     }   }     //delay by 2s. Meaning we will be sent values every 2s approx   //also means that it can take up to 2 seconds to change LED state   delay(2000); void readSensor2() {   total = total - readings[index];     readings[index] = analogRead(A0);     total = total + readings[index];     index = index + 1;     if (index >= numReadings)   {      index = 0;   }     average = total / numReadings;        //sensorValue1 = (analogRead(A0) - 330)* i;    //delay(200);         Serial.println(average);    delay(100);          if( digitalRead(button) == HIGH && flag == 1)   {     flag = 0;     containerValue = 0;      }   else if (digitalRead(button) == HIGH && flag != 1) {   flag = 1;                        //when the button is pressed the initially sesnsor     containerValue = sensorValue1;      delay(10);   }     //Serial.println(digitalRead(button));    delay (1000);    } //sends the values from the sensor over serial to BT module void sendAndroidValues() {   //puts # before the values so our app knows what to do with the data Serial.print('#');   //for loop cycles through 4 sensors and sends values via serial   Serial.print(sensorValue1);   Serial.print('+');     //technically not needed but I prefer to break up data values     //so they are easier to see when debugging Serial.print('~'); //used as an end of transmission character - used in app for string length Serial.println(); delay(5000);        //added a delay to eliminate missed transmissions } void printLCD() {   lcd.setCursor(4, 0);   lcd.print("   GRAMS    ");   lcd.setCursor(4, 1);   lcd.print(sensorValue1); }

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


This arduino code does not work as expected, any help? there seems to be an issue with the digitalWrite function. Answered

Recently, I wanted to make a laboratory grade linear semi-precision power supply using an Arduino, LCD, some comparators, and MOSFETs. Idealistically, I want measurements to be 3 significant figures of precision (0.1% accuracy @ 30V), voltages as high as 30V, and max current of 10A. The power supply is most likely going to be just a single regulated output, maybe if I feel lucky I will make 2 regulated outputs once I get the darn Arduino code to work. The Arduino's job is to simply set and read the output voltage, and is not part of the control loop. That is what the comparators are for. (I learned the hard way that using the Arduino within the control loop just results in parasitic oscillations because the Arduino is a clocked device and can only self correct at timed intervals.) Anyway, below is the code. I made explanations of all portions of it as clear as possible, and I also give the wiring used for the LCD, 4 buttons, and analog inputs used to set and read the voltage and current. However, the issue arises when I upload the code, the setVI button does not work unless I press both it and the RS button at same time. I made the many of the integers display in the serial output to diagnosing easier hopefully. I can see the setVI integer and my dudd integer only goes HIGH when  either it and the RS buttons are pressed simultaneously, or when the RS butten is held down for a long enough time. However, as far as I am aware, nowhere in the code do I manipulate that code so setVI goes HIGH dependant on other buttons, so I am bewildered by this parasitic phenomenon. Is my Arduino MEGA broken? I had a similar problem in the past, where I had multiple analogRead statements It strangely seemed to factor in the outputs of other input pins. Anyway, here is the code. Maybe someone could upload it and tell me if it functions properly on their arduino? That would help me determine if it is indeed a software issue. (p.s. I use an Arduino ripoff called the Funduino, but it is not broken in any way, I don't think?) Any and all help would be greatly appreciated, thank you in advance, -Max-. p.s. To make the code below legible, please copy/paste it in an IDE or in notepad and convert it into a monospaced font, it will make it very easy to follow. //---------------------------------------------------------------------------------------------------------------// /* Arduino Software for lab power supply. Wireing guide:        **Wiring for 16x2 LCD:**       * LCD RS pin to digital pin 12       * LCD Enable pin to digital pin 11       * LCD D4 pin to digital pin 5       * LCD D5 pin to digital pin 4       * LCD D6 pin to digital pin 3       * LCD D7 pin to digital pin 2       * LCD R/W pin to ground       * 10K resistor:       * ends to +5V and ground       * wiper to LCD VO pin (pin 3)    **Wiring for buttons:**       * RS       button to pin 6  (as a digital input) -- Switches from reading read current/voltage values to setting those values, and Vice Versa.       * VIselect button to pin 7 (as a digital input) -- Switches to the 'set' mode and flips from setting the voltage to setting the current.       * UP       button to pin 8  (as a digital input) -- Increments the voltage or current up when in the 'set' mode.       * DOWN     button to pin 9  (as a digital input) -- Increments the voltage or current up when in the 'set' mode.    **Analog inputs/outputs:**       *A0   -- Measures a potential of a resistor divider that can output a voltage of 0-5V based on the 0-30V output this PSW capable of.       *A1   -- Measures the current flow through a resistor to measure current. (Some reason there seems to be a pulldown resistor on this pin, so the voltage does not float.)       *Vout -- This will be later implemented if I get a DAC, for the increased resolution. (1024 is just not enough in my opinion. At least 12 bits)       *Aout -- This will be later implemented if I get a DAC, for the increased resolution. (1024 is just not enough in my opinion. At least 12 bits) */ int UP    = 0;      // These are the 2 buttons used to incrementally int DOWN  = 0;      // step up or down the voltage on the output int RS = 0;         // These 2 buttons tell the LCD to either read out the voltage on the analog pins. (I plan to change this so it reads from a 14 bit ADC and writes int setVI = 0;      // the voltage output through a 14 (or 16 bit) bit ADC. I need 3 significant digits, or at least 0.1% accuracy. int dudd = 0;       // this dudd (dummy variable) is just here to prove that digitaslreading pin 7 works very weird! Any help on this? int preRS = 1;      // Anything with a "Pre" before it is simply what said integer/variable on the last loop. I use these to prevent a parasitic int presetVI = 1;   // oscillation of states that they control, so when a button is pressed, it will not jump between 2 states every cycle. int preUP    = 0; int preDOWN  = 0; float Aset = 0.00;  // I need these to be "floated" so I can set the exact value of these to 3 significant digits. float Vset = 0.00;  // Aset and Vset define what the output voltage *should* be, and are defined with the UP/DOWN buttons. int VIselection = 1;// this variable will invert when Aset button is pressed. Similar to the IVselect, this number will also invert int READorSET = 1;  // Bset button is pressed. This allows the mode to be changed from SET mode or the READ output mode, thus allowing                     // one to compare the output voltage and current to the set value, as well as set the output voltage and current. #include LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// initialize the library with the numbers of the interface pins void setup() { //-------------------------// I tried making diagnosting this thing easier by making all the important data availible in the serial monitor.   lcd.begin(16, 2);   Serial.begin(9600);   Serial.print("INPUTS         RS:           READorSET:       setVI & dudd:        VIselection:");   Serial.println(""); } void loop() {   float V = (30.00*analogRead(A0))/1024.00;   //These are what I use to read the voltage output of my power supply. I will have a voltage divider on the output,   float A = (15.000*analogRead(A1))/1024.000; //to limit the voltage range from 0-30V to 0-5V. Same concept goes for the current measurement.   int dudd  = digitalRead(7);//   RS    = digitalRead(6);//RS stands for "Read/set"   setVI = digitalRead(7);//VI is stands for "Current/Voltage set"   UP    = digitalRead(8);//UP is simply a button used to set voltage & current   DOWN  = digitalRead(9);//DOWN is simply a button used to set voltage & current     if(presetVI == LOW && setVI == HIGH){VIselection = -VIselection;}   if(preRS    == LOW && RS    == HIGH){READorSET   =   -READorSET;}     Serial.print("\t        ");  // prints an inital space.     Serial.print(RS);            // prints the RS reading. It should be '1' when pin 7 is HIGH.     Serial.print("\t        ");     Serial.print(READorSET);     // prints the READorSET reading. This should only change when the RS button is pressed.     Serial.print("\t        ");     Serial.print(setVI);         // prints the setVI reading. It should be '1' when pin 7 is HIGH.     Serial.print("\t");     Serial.print(dudd);         // prints the setVI reading. It should be '1' when pin 7 is HIGH.     Serial.print("\t        ");     Serial.println(VIselection); // prints the VIselection reading. This should only change when the setVI button is pressed.         //if(presetVI == LOW && setVI == HIGH && READorSET == 1) {READorSET = -READorSET; VIselect = -VIselect;}      // This line of code just makes so that when I need to go from the voltage read screen to      // the set mode, I can just press the VIselect button. It just makes things more intuitive, but could be      // causeing the error, so I nulled it. I also nulled it out another portion that will keep the voltage or      // current setting the same when using the VI buttton to select the set mode. (otherwise it has to be      // double pressed to return to, say, the current setting, if that is where you left off.)   if(UP == HIGH && DOWN == LOW && VIselection == -1){if(Aset <= 10.00) {Aset += 0.05;}}   if(DOWN == HIGH && UP == LOW && VIselection == -1){if(Aset >= 0.10) {Aset -= 0.05;}}     if(UP == HIGH && DOWN == LOW && VIselection == 1) {if(Vset <= 30.00) {Vset += 0.05;}}   if(DOWN == HIGH && UP == LOW && VIselection == 1) {if(Vset >= 0.05) {Vset -= 0.05;}}     if (RS == HIGH){digitalWrite(13, 1);}   if (RS == LOW){digitalWrite(13, 0);} //============================================================================================================//   if (READorSET == 1){      //this is the defualt screen, and shows the output voltage and current.     lcd.clear();              lcd.setCursor(0, 0);     lcd.print("VOLTAGE:");     lcd.setCursor(0, 1);     lcd.print("CURRENT:");     lcd.setCursor(10, 0);     lcd.print(V);     lcd.setCursor(15, 0);     lcd.print("V");     lcd.setCursor(10, 1);     lcd.print(A);     lcd.setCursor(15, 1);     lcd.print("A");   }   if (READorSET == -1){   // This is the portion of the code allowing me to set the current and voltage     lcd.clear();          // using the up/down buttons.       if (VIselection == -1){         lcd.setCursor(0, 0);         lcd.print("  SET CURRENT:");         lcd.setCursor(5, 1);         lcd.print(Aset);         lcd.print("A ");       }       if(VIselection == 1){         lcd.setCursor(0, 0);         lcd.print("  SET VOLTAGE:");         lcd.setCursor(5, 1);         lcd.print(Vset);         lcd.print("V ");       }   } //============================================================================================================//   presetVI = setVI; // At the end of each loop, the current variable settings that were used are set equal   preRS = RS;       // to the 'pre' versions of the code. This allows me to basically measure the when                     // the button is initially pressed, and/or released. Using this method with the delay()                     // function, however, is a bit buggy, but I did have it working well enough before. If you                     // tap the button too quickly. You almost have to hold it for a split second. If you                     // know a better, simpler way of doing this, please tell me, thank you.                       delay(80);        // The delay helps stabilize the reading on the LCD, but if it is too large, than the                     // refresh rate suffers, and the buttons respond slower. However, setting too low will                     // cause the reading on the display to change so rapidly, it is illegible. }

Question by -max- 5 years ago  |  last reply 5 years ago