element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Sending multiple data from AppInventor to Arduino?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 10 replies
  • Answers 9 answers
  • Subscribers 391 subscribers
  • Views 2713 views
  • Users 0 members are here
  • arduino
Related

Sending multiple data from AppInventor to Arduino?

bopele
bopele over 6 years ago

I have 2 LEDs. With Slider1, I will adjust the brightness of one, Slider2 and the other. When I press these buttons in Animation 1 or Animation 2, the LEDs will light up in various ways. I have received data from Slider1 and Slider2, but how do I make changes to the AppInventor and Arduino code to receive and use the button data?

imageimage

image

  • Sign in to reply
  • Cancel

Top Replies

  • BigG
    BigG over 6 years ago +2 suggested
    Have you thought about what Arduino is receiving exactly. Remember, Arduino has no idea how you have designed the app. It just receives data from the Bluetooth Connection. So how are you telling Arduino…
  • BigG
    BigG over 6 years ago in reply to bopele +2 suggested
    It is pretty easy. As you are sending text via the"call BluetoothClient1.SendText" option, just prefix what you have in the "Join" with something you can parse out on the Arduino side. For Example, for…
  • neilk
    neilk over 6 years ago +1 suggested
    Hi bopele ane welcome to element14 It would help if you can explain what you actually want to do when the button(s) are pressed. Neil
Parents
  • BigG
    0 BigG over 6 years ago

    Have you thought about what Arduino is receiving exactly.

     

    Remember, Arduino has no idea how you have designed the app. It just receives data from the Bluetooth Connection. So how are you telling Arduino this data is from Animation1 or Slider1 or Animation2 etc. You need to add in an identifier for example as all you are sending at present is a value.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • bopele
    0 bopele over 6 years ago in reply to BigG

    So I don't know exactly how to add this "identifier". image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • BigG
    0 BigG over 6 years ago in reply to bopele

    It is pretty easy.

     

    As you are sending text via the"call BluetoothClient1.SendText" option, just prefix what you have in the "Join" with something you can parse out on the Arduino side.

     

    For Example, for the Blue Slider you could use:

    Join

    - "Sb"

    - round(blueSlide.thumbposition)

    - "\n"

     

    For the Orange Slider you could use:

    Join

    - "So"

    - round(orangeSlide.thumbposition)

    - "\n"

     

    For the Blue Button (Animation1) it will be even easier - so with the Animation1.click, just sent this text "Ab\n"

     

    Then on Arduino side:

     

    You need to first "read" what is available via Bluetooth (your code does not show this) and place or append the character you have just read into a variable of String type.

     

    If you look in String object you will see a function startsWith()

     

    This is a handy function as you can now check if the string you've just received "startsWith" Sb and if so you know from this identifier it is Slider blue. If it "startsWith" Ab you know that is the Animation Blue button etc.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • bopele
    0 bopele over 6 years ago in reply to BigG

    Actually, I used the startsWith () function before, but I encountered a problem. There was no problem sending the data, but when I press the "button" from the phone, the operations in the void loop() (the section of DigitalWrite (11, HIGH)...) are stopped for a while.  How can I fix it?

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • BigG
    0 BigG over 6 years ago in reply to bopele

    At the moment the picture showing your App Inventor blocks does not show any functions attached to the buttons (Animation1 and Animation2) so based on what you sent the buttons are not doing anything.

     

    bopele  wrote:

     

    There was no problem sending the data, but when I press the "button" from the phone, the operations in the void loop() (the section of DigitalWrite (11, HIGH)...) are stopped for a while.  How can I fix it?

    image

     

    I'm not sure what you mean by "Stopped for a while". Is it more than delay(200) but it has not stopped indefinitely. Anyhow, I think I know what is happening as you are using the "readString" function. You need to look at how the readString function terminates, as in, knows when it has received all the text string data and returns this back to you.

     

    In my experience this is not a good function to use when streaming data.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 6 years ago in reply to bopele

    Your first solution - just for reading the sliders -  is fine as far as it goes, but it is dependent on always sending two integers, always in the same order. Your AppInventor code could be a little simpler but never mind it works!

     

    As BigG said, if you want to send some other, different data items as well, you will need to identify each data item with a prefix so that you can sort them out in the arduino code and act accordingly

     

    You say the above code snippet didn't work properly. You need to show the relevant AppInventor blocks and also copy and paste your Arduino code into the posting, rather than insert an image.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 6 years ago in reply to bopele

    Remember that AppInventor is EVENT driven. Each slider movement and each button press is an independent event and as such can trigger the transmission of a single. identifiable piece of data to the arduino.

     

    So, instead of sending both slider positions and both button presses every time any event is triggered, just send the one responsible for the trigger, preceded by a suitable identifier. If you use a single character identifier (that gives you plenty of scope!), decoding the result in the arduino sketch will be very easy - eg, you could use a case statement.

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • neilk
    0 neilk over 6 years ago in reply to bopele

    Remember that AppInventor is EVENT driven. Each slider movement and each button press is an independent event and as such can trigger the transmission of a single. identifiable piece of data to the arduino.

     

    So, instead of sending both slider positions and both button presses every time any event is triggered, just send the one responsible for the trigger, preceded by a suitable identifier. If you use a single character identifier (that gives you plenty of scope!), decoding the result in the arduino sketch will be very easy - eg, you could use a case statement.

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube