Particle Argon Lcd

argon
Tags: #<Tag:0x00007fe21f377068>

#11

What should I do now?


#12

Can anybody here tell me how to get an I2C 1602 lcd work with Argon. Please send a working circuit diagram and program for it.


#13

@Vilaksh, did you understand what @ScruffR told you that chances are, you have damaged the I2C port on your Argon? If not, re-read this topic and do not continue until you do understand.

If you want to interface a 5V I2C display (like yours) to an Argon, you will need the following:

  1. A 5v-3.3v level shifter like the one recommended by @shanevanj:

The connection is as follows:

Boron    Arduino    Level Shifter    I2C Display
------------------------------------------------
3V3                      LV
GND                      GND
            5V           HV             Vcc
            GND          GND
GND         GND                         GND
SCA                      A1
SCL                      A2
                         B1             SCA
                         B2             SCL

You will not need I2C pull-up resistors if you use this board (it has them built in).

  1. If you power the display from a separate 5v source like an Arduino, you will need to connect the Arduino GND to the Argon GND.

You MUST have this in place BEFORE you apply power to your circuit.


#14

Thank you all for your guidance. I made it work. Luckily my argon pins were not damaged and I can work with it now.


#15

Also I want to read some data using webhook and display on lcd, I have some json data from google sheets (using gsxtojson I made an integration) in form of a list is it possible to show it up on lcd. Any demo code for that.


#16

If you want help - you need to also attempt a few things - we don’t do the work for you. So post some code.

Secondly don’t double post - its just wastes everyones time


#17

Thridly - I may add - try to read, understand and apply the given advice.

You still haven’t resolved the 5V issue - the I2C board on the display has its own 5V pull-up resistors and you added another set of 3.3V pull-ups resulting in a level greater 3.3V on your GPIOs and also “back-feeding” into the 3.3V supply on the Argon.


#18

I am not able to get you. Would you please explain me.


#19

I’m not sure if there is a way to clarify this more than @peekay123 did but i’ll will try.
On the attached picture you have Pololu logic level shifter you just need to use for example L1->SCL L2->SDA on 3,3V site and H1-> SCL H2-> SDA on 5V site that’s it. And of course connect 3,3V to LV and 5V to HV and GND.


#20

Got it. One more thing how to fix this error


#21

A recipe to fix any error is to investigate.

I’m absolutely certain (I have checked :wink: ) the ArduinoJson library features an example that shows how to properly get a string from a JsonVariant object.


#22

as mentioned by @ScruffR, all you need is here: arduinojson.org/v5/example/parser/


Sometimes it’s good to dig a little deeper by self and be a little more patient before we asking a question.
Also you are iterating over an json object values which belongs to key: “crops” (will be easier if we can see example of your json ) you have to consider that after “for” is done your “text_var” it’s gonna be equal to the lastest value of {“crops”: [“foo”,“bar”,…,“22nd_value”] }


#23

This is thr json data from integration



#24

This doesn’t seem to be valid JSON.

The keys need to be strings (wrapped in double quotes) and each individual field in your array ([...]) should be wrapped in curly braces ( [ {"0":"PADDY"}, {"1":"JOWAR"}, ...])
You should feed your pseudo JSON into a online parser to get that sorted before moving on.


#25

I was able to compile the test code with no errors for my argon. let’s say that you fix your json and it’s looks similar to this:
{
“columns”: {
“crops”: [
{“0”:“PADDY”},
{“1”:“JOWAR”},
{“2”:“BAJRA”},
{“3”:“MAIZE”}],
“rates”: [
{“0”:1750},
{“1”:2430},
{“2”:1950},
{“3”:1700}]
}
}

// This #include statement was automatically added by the Particle IDE.
#include <SparkJson.h>

const size_t capacity = 2*JSON_ARRAY_SIZE(4) + 9*JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + 90;

StaticJsonBuffer<capacity> jsonBuffer;

char* json = "{\"columns\":{\"crops\":[{\"0\":\"PADDY\"},{\"1\":\"JOWAR\"},{\"2\":\"BAJRA\"},{\"3\":\"MAIZE\"}],\"rates\":[{\"0\":1750},{\"1\":2430},{\"2\":1950},{\"3\":1700}]}}";

void setup() {

}

void loop() {
    
JsonObject& root = jsonBuffer.parseObject(json);

JsonArray&  cropsArray = root["columns"]["crops"];
JsonArray& ratesArray = root["columns"]["rates"];

const char* columns_crops_0_0 = cropsArray[0]["0"]; // "PADDY"
    Serial.println(columns_crops_0_0);
const char* columns_crops_1_1 = cropsArray[1]["1"]; // "JOWAR"
    Serial.println(columns_crops_1_1);
const char* columns_crops_2_2 = cropsArray[2]["2"]; // "BAJRA"
    Serial.println(columns_crops_2_2);
const char* columns_crops_3_3 = cropsArray[3]["3"]; // "MAIZE"
    Serial.println(columns_crops_3_3);

int columns_rates_0_0 = ratesArray[0]["0"]; // 1750
    Serial.println(columns_rates_0_0);
int columns_rates_1_1 = ratesArray[1]["1"]; // 2430
    Serial.println(columns_rates_0_0);
int columns_rates_2_2 = ratesArray[2]["2"]; // 1950
    Serial.println(columns_rates_0_0);
int columns_rates_3_3 = ratesArray[3]["3"]; // 1700

// or.......

for(JsonObject& result : cropsArray){

   JsonObject& crops = result;
   
   Serial.println(crops["0"].as<const char*>()); // "PADDY"
   Serial.println(crops["1"].as<const char*>()); // "JOWAR"
   Serial.println(crops["2"].as<const char*>()); // "BAJRA"
   Serial.println(crops["3"].as<const char*>()); // "MAIZE"
  

}

for(JsonObject& result : ratesArray){

   JsonObject& rates = result;
   
   Serial.println(rates["0"].as<int>()); // 1750
   Serial.println(rates["1"].as<int>()); // 2430
   Serial.println(rates["2"].as<int>()); // 1950
   Serial.println(rates["3"].as<int>()); // 1700
   
  

}


}

I used https://arduinojson.org/v5/assistant/ which is preatty usefull tools. and https://arduinojson.org/v5/doc/decoding/ to learn how
to deal with json.
Please note that I did not tested / flashed this code to my argon !!!


#26

Use a logic level shifter. that is the first thing that you should be doing. They are inexpensive and they will save your project. If you do not know how to set one up, that is OK, we can show you. With 5v and 3.3v, you risk destroying your project. at higher voltages and larger currents, you risk fire.


This is one way that you could hook up a logic level shifter to convert 5 and 3.3 volts.
You give the shifter power from both sets of voltage, then you feed it signal voltage on the correct side: 3.3v signal goes to the 3.3v power side and 5v signal to the 5v side.

Please note, i have no idea what your lcd pins should be, so they are just attached where it looked convenient. Also, I do not have a fritzing model for the xenon, only the photon and electron. You can set the pinouts to your xenon just by the pin name.


#27

I am unable to fix my json. Will this be a valid one.`

{"rows":[{"crops":"PADDY","rates":1750},{"crops":"JOWAR","rates":2430},{"crops":"BAJRA","rates":1950},{"crops":"MAIZE","rates":1700},{"crops":"RAGI","rates":2897},{"crops":"ARHAR(Tur)","rates":5675},{"crops":"MOONG","rates":6975},{"crops":"URAD","rates":5600},{"crops":"COTTON","rates":5150},{"crops":"GROUNDNUT IN SHELL","rates":4890},{"crops":"SUNFLOWER SEED","rates":5388},{"crops":"SOYABEAN","rates":3399},{"crops":"SESAMUM","rates":6249},{"crops":"NIGERSEED","rates":5877},{"crops":"WHEAT","rates":1840},{"crops":"BARLEY","rates":1440},{"crops":"GRAM","rates":4620},{"crops":"MASUR (LENTIL)","rates":4475},{"crops":"RAPESEED/MUSTARD","rates":4200},{"crops":"SAFFLOWER","rates":4945},{"crops":"TORIA","rates":4190},{"crops":"JUTE","rates":3700},{"crops":"SUGARCANE $","rates":275}]}

#28

This is valid.

Use https://jsonlint.com to validate any Json. documents


#29

I made one more test code which successful parse jour new json and flashed my Argon then publish results witch Particle.publish() . All works perfect !. Please note i’m not a programmer ! I even never “stood beside any professional one”, so the code is just for demonstrating the idea how to deal with json also parseFunc() will block for 24s maybe @ScruffR can add/correct something whch supose to be done in diffrent/easiest way.

// This #include statement was automatically added by the Particle IDE.
#include <SparkJson.h>
#include "Particle.h"

unsigned long  interval = 5000; 
char* json = "{\"rows\":[{\"crops\":\"PADDY\",\"rates\":1750},{\"crops\":\"JOWAR\",\"rates\":2430},{\"crops\":\"BAJRA\",\"rates\":1950},{\"crops\":\"MAIZE\",\"rates\":1700},{\"crops\":\"RAGI\",\"rates\":2897},{\"crops\":\"ARHAR(Tur)\",\"rates\":5675},{\"crops\":\"MOONG\",\"rates\":6975},{\"crops\":\"URAD\",\"rates\":5600},{\"crops\":\"COTTON\",\"rates\":5150},{\"crops\":\"GROUNDNUT IN SHELL\",\"rates\":4890},{\"crops\":\"SUNFLOWER SEED\",\"rates\":5388},{\"crops\":\"SOYABEAN\",\"rates\":3399},{\"crops\":\"SESAMUM\",\"rates\":6249},{\"crops\":\"NIGERSEED\",\"rates\":5877},{\"crops\":\"WHEAT\",\"rates\":1840},{\"crops\":\"BARLEY\",\"rates\":1440},{\"crops\":\"GRAM\",\"rates\":4620},{\"crops\":\"MASUR (LENTIL)\",\"rates\":4475},{\"crops\":\"RAPESEED/MUSTARD\",\"rates\":4200},{\"crops\":\"SAFFLOWER\",\"rates\":4945},{\"crops\":\"TORIA\",\"rates\":4190},{\"crops\":\"JUTE\",\"rates\":3700},{\"crops\":\"SUGARCANE $\",\"rates\":275}]}";

void parseFunc(char *data); // forward declaration



void setup() {
	char *dataCopy = strdup(json);
	parseFunc(dataCopy);
	free(dataCopy);


}


void parseFunc(char *mutableData) {
   const size_t capacity = JSON_ARRAY_SIZE(23) + JSON_OBJECT_SIZE(1) + 23*JSON_OBJECT_SIZE(2) + 670;
   StaticJsonBuffer<capacity> jsonBuffer;
   JsonObject& root = jsonBuffer.parseObject(mutableData);
   JsonArray& rowsArray = root["rows"];
   
   if(!root.success())
    {
        Particle.publish("parse failed",PRIVATE);
    }
    else 
    {
   
    for(JsonObject& result : rowsArray){

       JsonObject& rows = result;
       Particle.publish("crops", rows["crops"].asString(), 60, PRIVATE); //as<const char*>()
       Particle.publish("rates", String(rows["rates"].as<int>()), 60, PRIVATE);
       delay(1000);
       
       }
    } 
} 

void loop() {
    
if (millis() - interval > 5000) {
    
    char *dataCopy = strdup(json);
	parseFunc(dataCopy);
	free(dataCopy);
   
    interval = millis();
    
   }
  
}

and results:


#30

This is the spirit we want to encourage :+1:
Just get your hands dirty and try - this way you learn the most.

That’s why I said this earlier

Spoon-feeding solutions hardly encourages people to try to understand - when they have to put effort into investigation the understanding is a by-product and the acquired knowledge will stick with you much longer and the next problem will take you only a fraction of the time to find the solution.

You probably know the parable about it beeing better to teach someone to fish than just giving him one fish.