1

I'm trying to write a simple string on the first line of a LCD screen just using the standard GPIO library and so far I can't figure out how to print a string and a variable on the same line with python, so far I can use it in this way:

lcd_string("A simple string",LCD_LINE_1)

and

lcd_string(aSimpleVariable,LCD_LINE_1)

but it seems I can't find the correct way to print the string and the variable on the same line, can anyone please point me in the right direction? Thanks in advance

1

Try this lcd_string("your text " + str(yourVar), 1) Use str() to make sure your variable is passed as string, than paste both together with concatenation operator +. The second parameter is indicating the line in your display. Many people use two line LCD displays, in this case 1 would address the first line and 2 the second line in your display.

  • Looks just about OK, but did you change the second parameter from LCD_LINE_1 on purpose? It would also be worth including a very brief explanation on what you're doing with the concatenation operator. – goobering Feb 2 '17 at 18:01
  • The second parameter is just for addressing the line in your display. 1=first, 2 =second line etc – Stowoda Feb 2 '17 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.