Shop OBEX P1 Docs P2 Docs Learn Events
New at working with Parallax code — Parallax Forums

New at working with Parallax code

CreeCree Posts: 132
edited 2013-06-07 13:47 in BASIC Stamp
Hi, i'm doing an internship at a company and I need help understanding the code for the BS2sx. I have done programming before, but in C. So I understand some of it, but not enough to do what I need to do.

I have been trying out demo codes for the BS2sx stamp.

I have gotten the sensor and LCD to work separately with demo codes.

I'm using
NX1000 (stamp works experiment board)
Bs2sx
Sensirion temperature and humidity sensor (SHT11)
and a 2x16 LCD screen

I used this code for the sensor from this link

http://www.emesystems.com/BS2math1.htm

and
this link for the LCD (BS2)

http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/lcd2x16par.pdf


I have to display temperature and humidity onto an 2 x 16 LCD I have
and
I have no idea on how to do it, I have tried to find something to help me.
is there any content that can help me learn and understand the code?


(Later I need to make alarm with an LED and change the set point the alarm with push buttons. I also need to use multiple sensors (any pointers on how to do addressing of sensors to collect multiple points of measurement.)



any help would very useful. :thumb:

Comments

  • bsjohnbsjohn Posts: 19
    edited 2013-05-31 19:32
    New to PBasic is a fairly common question in this forum. Just browse back a few pages and you'll find all the links you'll need to familiarize yourself. Parallax has many free downloads to get you started, with well documented examples.
    Work on understanding each piece of your project separately, then put them together.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-31 21:51
    As usual for Parallax products, there are links on the webpage for each product to sample code. For the SHT11, I'm sure the example uses the DEBUG statement while the LCD example demonstrates how to display characters one at a time. The "What's a Microcontroller?" tutorial and the "Basic Stamp Syntax and Reference Manual" are the usual startup references available from the Download webpage on Parallax's website. The DIG operator in PBasic is what you'd use to get the decimal digits from a numeric value in a variable for display.
  • CreeCree Posts: 132
    edited 2013-06-03 06:27
    K, I'll continue what I was doing before studying different example codes.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2013-06-03 09:54
    As Mike mentioned (thanks Mike!) "What's a Microcontroller" is the beginning programming tutorial for the BASIC Stamp. It is included as a PDF under the Help menu in the BASIC Stamp Editor (if you have an up-to-date version, see www.parallax.com/basicstampsoftware).

    For examples that show using the 2x16 Serial LCD to display sensor output, see Smart Sensors & Applications. It is discontinued but you can still download the PDF from here for the time being:

    Keep in mind that these books are written for the BS2. The BS2sx is a more capable microcontroller, and there are going to be additional commands available, and different units used in the arguments for each time-sensitive command. A summary of the time-sensitive commands, and tips for adjusting code examples from one model to another, are available in the BASIC Stamp Editor Help's PBASIC Language Reference. The article is called "Adapt BS2 Code to Other Models"

    I wish you the best with your internship!
  • CreeCree Posts: 132
    edited 2013-06-03 12:29
    thx steph

    I almost have it working to display temperature and humidity, I'm just not able to figure out how to send my data to the LCD
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-03 12:47
    The documentation for the LCD that you provided a link for has sample code for the BS2sx that sends one character at a time to the LCD. As I mentioned, the DIG operator will isolate the individual digits of a number. To display a digit, just add "0", then send the result (in temp) to the LCD using the Send_Text routine in the sample code like this
    for index = 4 to 0 step 1   ' from most significant to least significant
       Char = (temp DIG index) + "0"   ' convert a specific digit to a character
       gosub Send_Text   ' send to the LCD
    next index
    
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2013-06-03 12:51
    How about focusing on each sub-task first:

    1. Have you been able to display temperature and humidity data from the Sensirion in the BASIC Stamp Editor's Debug Terminal?
    2. Have you been able to display anything at all on the LCD?

    If you can first verify those two are working okay independently, it will be much simpler to figure out why there are not working together.
  • CreeCree Posts: 132
    edited 2013-06-03 12:56
    I got some words on the lcd, but its a bit messed up.
  • CreeCree Posts: 132
    edited 2013-06-03 12:59
    How about focusing on each sub-task first:

    1. Have you been able to display temperature and humidity data from the Sensirion in the BASIC Stamp Editor's Debug Terminal?
    2. Have you been able to display anything at all on the LCD?

    If you can first verify those two are working okay independently, it will be much simpler to figure out why there are not working together.


    Yes I have, I'm going to look into what mike posted.
  • CreeCree Posts: 132
    edited 2013-06-05 10:30
    I have been trying to get the temperature to display on my LCD screen that works.

    How do you set up the program to display the Celsius variable (tC which I believe has the temperature in Celsius)

    I'm using the B2sx LCD program from the previus link at the top

    &
    this is the link to the temperature code

    http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/SensirionDocs.pdf
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-05 10:51
    It's not our job here to write a specific program for you. It's our task to point you to the appropriate references and examples and start you on a path to learn how to program a Stamp in this case and to make use of the sample code that's available. Posts #3 and #5 do this.

    The section of the LCD program that starts with Main: is what you want to change and tC has the temperature in tenths of a degree Celsius. You'll have to take the temperature code, put the subroutines at the end of the LCD subroutines and put the temperature initialization code with the LCD initialization code. You'll have to combine the various variable and constant declarations as well. If you end up with too many variables, you'll have to figure out which variables are needed for which portions of the code and share them as needed using what's called aliases (see the Reference Manual for a description).

    To output something like xxx.x from tC, you'd take what I showed in Post #7 and add a decimal point like this
    FOR index = 3 to 0 step 1
       IF index = 0 THEN   ' Display a decimal point before the tenth's digit
          Char = "."
          GOSUB Send_Text
       ENDIF
       Char = (tC DIG index) + "0"
       GOSUB Send_Text
    NEXT index
    
    If you want to do zero suppression, you'll have to display spaces instead of zeros until the first non-zero digit is displayed. You'll need another (bit) variable to remember whether a non-zero digit has been displayed. The details are "an exercise for the reader". Remember that the decimal point should behave like a non-zero digit for this purpose.

    If you really want to understand how to use the BS2sx, as Steph mentioned, you have to work through the "What's a Microcontroller?" tutorial with the Reference Manual at hand. Unless you're an experienced programmer, it's never enough to just look at a specific device's code. You have to try things out starting simply until you understand how things work.
  • CreeCree Posts: 132
    edited 2013-06-05 13:06
    Thx for you help I finally got the temperature value onto the screen.
  • CreeCree Posts: 132
    edited 2013-06-06 08:06
    Thx for all the help, I got my LCD displaying the tem[perature, humidity as it changes and I have room for an adress that does not have a decimal point while the measurements do.


    How do u change the post solved? :)
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-06 08:45
    You click on Edit Post for your 1st message, then click on the Go Advanced button. You'll see that you can change the thread prefix.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2013-06-07 09:31
    Congratulations on getting that working, Cree! And thank you so much for setting this to "solved" - people don't always remember to do that.
  • CreeCree Posts: 132
    edited 2013-06-07 13:47
    thx, but now I going to need to do this with multiple sensors with an IO expander. I'm going to make another thread for that.
Sign In or Register to comment.